[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Facebook error

Posted on 2014-08-09
2
Medium Priority
?
220 Views
Last Modified: 2014-11-29
Hi Guys

I have th below code and i am trying to post to a fan page on facebook but it gives me an error of("invalidate parameters")

Please can you assist?

try
        {
            string app_id = "xxxxxxx";
            string app_secret = "xxxxxxxxxxxxxxxxxxxxx";
            string scope = "publish_stream,manage_pages";

            if (Request["code"] == null)
            {
                Response.Redirect(string.Format("https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}", app_id, Request.Url.AbsoluteUri, scope));
            }
            else
            {
                Dictionary<string, string> tokens = new Dictionary<string, string>();

                string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}", app_id, Request.Url.AbsoluteUri, scope, Request["code"].ToString(), app_secret);

                HttpWebRequest request = System.Net.WebRequest.Create(url) as HttpWebRequest;

                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    StreamReader reader = new StreamReader(response.GetResponseStream());

                    string vals = reader.ReadToEnd();

                    foreach (string token in vals.Split('&'))
                    {
                        //meh.aspx?token1=steve&token2=jake&...
                        tokens.Add(token.Substring(0, token.IndexOf("=")), token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
                    }
                }

                string access_token = tokens["access_token"];

                var client = new FacebookClient(access_token);

                var parameters = new Dictionary<string, object>();

                parameters["picture"] = "http://www.yaplex.com/logos/yaplex-logo-with-text-small.png";
                //parameters["link"] = "http://yaplex.com/";
                //parameters["name"] = "[name] Facebook name...";
                //parameters["caption"] = " Facebook caption";
                //parameters["description"] = "[description] Facebook description...";
                parameters["message"] = "[message] Facebook message...";

                client.Post("/me/feed", parameters);

            }
        }
        catch (FacebookOAuthException ex)
        {
            //handle oauth exception
        }
        catch (FacebookApiException ex)
        {
            //handle facebook exception
        }

Open in new window

0
Comment
Question by:JCWEBHOST
2 Comments
 

Accepted Solution

by:
chirag zaptech earned 1500 total points
ID: 40356661
Please let me know what version of FB  API you are using and also version of PHP installed on you server where you are running this code. I think it maybe a version issue. I came across something like this before and it turned out to be the fact that the version of API we used for FB was not compatible with the PHP version we had on the server.
0
 

Author Closing Comment

by:JCWEBHOST
ID: 40471365
thanks i quit trying to fix it
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month20 days, 4 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question