lundi 30 mars 2015

How to resolve (OAuthException - #190) Error validating access token: This may be because the user logged out or may be due to a system error

I am trying to post on my Facebook fan page using Facebooh Graph API. To do this I am using extended Page access token. I was able to post my contents on Facebook, but the moment I logged out from administrator account and tried posting the contents on my Fan Page I am getting this error. Please guide me how can I resolve this issue?


To get Extended Page Access token I have followed these processes-



  1. Created an FB App to get AppID and AppSecret.

  2. Headed over to Facebook Graph API Explorer

  3. On the top right in "Application" I have selected my app which I have created.

  4. Clicked on Get Access Token Button

  5. Added "manage_pages" permission.

  6. Converted short-lived access token into a long lived one by making this Graph API http://ift.tt/1bsunJu LIVED TOKEN

  7. Grabbed new long lived access token returned back. Now I am using this long lived access token in my code. Please guide me how can I resolve this issue.


CS Code-



protected void Page_Load(object sender, EventArgs e)
{
CheckAuthorization();
}

private void CheckAuthorization()
{
string app_id = "XXXXXX";
string app_secret = "XXXXX";
//string my_url = "http://localhost:6943/ashish/Default2.aspx";
string scope = "publish_stream, publish_actions, manage_pages, email,user_location,user_birthday";
if (Request["code"] == null)
{
Response.Redirect(string.Format("http://ift.tt/IElFZM}", app_id, Request.Url.AbsoluteUri, scope));
}
else
{
Dictionary<string, string> tokens = new Dictionary<string, string>();
string url = string.Format("http://ift.tt/IElGg0}", app_id, Request.Url.AbsoluteUri, scope, Request["code"].ToString(), app_secret);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());

string vals = reader.ReadToEnd();

foreach (string token in vals.Split('&'))
{
tokens.Add(token.Substring(0, token.IndexOf("=")),
token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
}
string access_token = "Long Lived Access Token";
var client = new FacebookClient(access_token);
dynamic parameters = new ExpandoObject();
parameters.message = "xxxxxxxxxxxxxxxxxxxxxxxx";
parameters.link = "XXXXXXXXXXXX";
parameters.picture = "XXXXXXXXXXXXXXXXX";
parameters.name = "XXXXXXXXXXXXXXX";
parameters.caption = "XXXXXXXXXXX";
client.Post("/FB Fan page ID/feed", parameters);
}
}

Aucun commentaire:

Enregistrer un commentaire