开发者

"(190) Invalid OAuth 2.0 Access Token" when swhitching to Facebook c# sdk 5.0.8

After moving from v4 to v5.0.3, i'm switching to Facebook C# SDK v5.0.8 Beta

With the v5.03, i had:

                CanvasAuthorizer auth;
                var fb = new FacebookClient(appId, appSecret);

                if (!String.IsNullOrEmpty(_requiredAppPermissions))
                {
                    auth = new CanvasAuthorizer { Permissions = _requiredAppPermissions.Split(',') };
                }
                else
                {
                    auth = new CanvasAuthorizer();// { Permissions = RWE.Core.Config.FacebookPerms };
                }
                if (_AuthUrlCancel != "") auth.CancelUrlPath = _AuthUrlCancel;
                if (_AuthUrlReturn != "") auth.ReturnUrlPath = _AuthUrlReturn;

                if (auth.Authorize())
                {
                    fb = new FacebookClient(this.CurrentSession.AccessToken);
                    //do what i want
 开发者_JAVA技巧               }

Now, with the v5.0.8, it's not working and tells me :

(190) Invalid OAuth 2.0 Access Token at Facebook.FacebookClient.Api(String path, IDictionary2 parameters, HttpMethod httpMethod, Type resultType) at Facebook.Web.FacebookWebClient.Api(String path, IDictionary2 parameters, HttpMethod httpMethod, Type resultType) at Facebook.Web.FacebookWebContext.HasPermissions(String appId, String appSecret, Int64 userId, String[] permissions) at Facebook.Web.FacebookWebContext.IsAuthorized(String[] permissions) at Facebook.Web.FacebookWebAuthorizer.Authorize()


Sorry for the confusion. FacebookClient is not a direct substitution for FacebookApp. FacebookApp used to look at the session and get the access_token. FacebookClient does not do that.

I would suggest taking a look at this tutorial and you will find out the appropriate way to do this. But in short you need to do this:

var accessToken = FacebookWebContext.Current.AccessToken;
var client = new FacebookClient(accessToken);

or use FacebookWebClient like:

var client = new FacebookWebClient();

FacebookWebClient will handle getting the access token from the session for you. FacebookClient will not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜