如何使用其C#SDK更新Facebook访问令牌 [英] How to renew Facebook access token using its C# SDK

查看:116
本文介绍了如何使用其C#SDK更新Facebook访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢伟大的Facebook C#SDK,使我的工作处理Facebook API。
我正在使用sdk获取尽可能多的数据,例如帖子,评论,用户信息,尽可能从Facebook,但我的程序停止后,我的访问令牌在一段时间后过期,我必须重新启动程序。访问令牌来自 https://developers.facebook.com/tools/access_token/ ,但如何更新令牌?在 http://csharpsdk.org/docs/web/handling-expired中是TOTO -access-令牌的。有人可以帮忙解决这个问题吗?非常感谢你。

解决方案

这是我用来获得更长期限的令牌

  FacebookClient fbcl = new FacebookClient(atoken); 
fbcl.AccessToken = //您的短访问令牌;
fbcl.AppId = //您的应用程式ID;
fbcl.AppSecret = //你的应用程序秘密;

//尝试获取更长的令牌
尝试
{
动态结果= fbcl.Get(oauth / access_token?client_id = APP_ID& client_secret = APP_SECRET& grant_type = fb_exchange_token& fb_exchange_token =+ atoken);
atoken = result.access_token;
}
catch
{
动态结果= fbcl.Get(oauth / access_token?client_id = APP_ID& client_secret = APP_SECRET& grant_type = fb_exchange_token& fb_exchange_token =+ atoken);
atoken = result.access_token;
}

有时这会发出错误,如无法使安全的SSL连接FB或sth。所以我再试一次。也许你可以解决这个问题,并帮助我:)
干杯


Thanks for the great Facebook C# SDK which eases my work dealing with Facebook API. I'm using the sdk to fetch as much data, e.g. posts, comments, user info, from Facebook as possible, but my program stops after my access token expires after certain perior of time, and I have to restart the program. The access token is got from https://developers.facebook.com/tools/access_token/, but how can I renew the token? It is TOTO in http://csharpsdk.org/docs/web/handling-expired-access-tokens. Could anyone please help around this problem? Thank you very much.

解决方案

Here is what I use to get a longer expiring token

FacebookClient fbcl = new FacebookClient(atoken);
fbcl.AccessToken = //your short access token;
fbcl.AppId = //your app id;
fbcl.AppSecret = // your app secret;

//try to get longer token
try
{
    dynamic result= fbcl.Get("oauth/access_token?client_id=APP_ID&client_secret=APP_SECRET&grant_type=fb_exchange_token&fb_exchange_token=" + atoken);
    atoken = result.access_token;
}
catch
{
    dynamic result= fbcl.Get("oauth/access_token?client_id=APP_ID&client_secret=APP_SECRET&grant_type=fb_exchange_token&fb_exchange_token=" + atoken);
    atoken = result.access_token;
}

Sometimes this gives out an error like "Couldn't make secure SSL connection to FB" or sth like that. So I try it again in catch. Maybe you can solve this and help me too :) Cheers

这篇关于如何使用其C#SDK更新Facebook访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆