当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Im using facebook access token to post on my own page butnow im getting exception that my access token expired why?

问题描述:

private string PostFacebookWall(string accessToken, string message)

{

var responsePost = "";

try

{

//create the facebook account object

var objFacebookClient = new FacebookClient(accessToken);

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

parameters["message"] = message;

responsePost = objFacebookClient.Post("feed", parameters).ToString();

}

catch (Exception ex)

{

responsePost = "Facebook Posting Error Message: " + ex.Message;

}

return responsePost;

}

This is the method im using for posting.

I created the access token few hours ago and it was working no problems i could post messages on my wall no problems.

And now its humping to the CATCH and throw exception:

(OAuthException - #190) Error validating access token: Session has expired on 12 פברואר 2014 09:00. The current time is 12 פברואר 2014 14:27.

Facebook.FacebookOAuthException was caught

HResult=-2146233088

Message=(OAuthException - #190) Error validating access token: Session has expired on 12 פברואר 2014 09:00. The current time is 12 פברואר 2014 14:27.

Source=Facebook

ErrorCode=190

ErrorSubcode=463

ErrorType=OAuthException

StackTrace:

at Facebook.FacebookClient.ProcessResponse(HttpHelper httpHelper, String responseString, Type resultType, Boolean containsEtag, IList`1 batchEtags)

at Facebook.FacebookClient.Api(HttpMethod httpMethod, String path, Object parameters, Type resultType)

at Facebook.FacebookClient.Post(String path, Object parameters)

at ScrollLabelTest.Form1.PostFacebookWall(String accessToken, String message) in e:\scrolllabel\ScrollLabel\ScrollLabel\Form1.cs:line 266

InnerException:

Is there any way to get access token forever ? So it wont expired anymore ?

网友答案:

There are so-called short lived Access Tokens, which expire after two hours, and so-called long-lived Access Token which expire after 60 days. There's no way to receive non-expiring ones!

Apparanty you're using short-lived Access Tokens.

So the documentation here https://developers.facebook.com/docs/facebook-login/access-tokens/#termtokens and here https://developers.facebook.com/docs/facebook-login/access-tokens/#extending to see how you can exchange a short-lived to a long-lived one.

分享给朋友:
您可能感兴趣的文章:
随机阅读: