相关疑难解决方法(0)

在Android应用中获取刷新的Facebook令牌的代码是什么?

我正在开发一款Android应用.随着Facebook的offline_access权限即将弃用,我试图使用Graph API来扩展Facebook令牌.

        https://graph.facebook.com/oauth/access_token?             
        client_id=APP_ID&
        client_secret=APP_SECRET&
        grant_type=fb_exchange_token&
        fb_exchange_token=EXISTING_ACCESS_TOKEN
Run Code Online (Sandbox Code Playgroud)

任何人都可以提供详细的代码,演示如何将上述代码实现到Android应用程序并获取刷新的Facebook令牌?

感谢您的时间.

更新二:

进步(我想)!

使用带有facebook请求方法的完整URL会导致基本URL被添加到URL的开头而不是

String refreshUrl = "https://graph.facebook.com/oauth/access_token?client_id=12345678910&client_secret=abcdefghijklmnopqrstuvwxyz&grant_type=fb_exchange_token&fb_exchange_token="+currentAccessToken;
Run Code Online (Sandbox Code Playgroud)

应该用

String refreshUrl = "oauth/access_token?client_id=12345678910&client_secret=abcdefghijklmnopqrstuvwxyz&grant_type=fb_exchange_token&fb_exchange_token="+currentAccessToken;
Run Code Online (Sandbox Code Playgroud)

但是我现在收到响应{"error":{"message":"验证应用程序时出错.应用程序ID无效.","类型":"OAuthException","code":190}}

更新一:

这是我尝试过的.代码完成,即listerner上的OnComplete被调用,但响应不包含新的访问令牌或到期值.

    void refreshWithGraph() {
        AsyncFacebookRunner extendingAsyncRunner = new AsyncFacebookRunner(facebook);
        Bundle parameters = new Bundle();

        //the variable currentAccessToken is obtained after authorisation is complete using currentAccessToken = facebook.getAccessToken();

        String refreshUrl = "https://graph.facebook.com/oauth/access_token?client_id=12345678910&client_secret=abcdefghijklmnopqrstuvwxyz&grant_type=fb_exchange_token&fb_exchange_token="+currentAccessToken;


    extendingAsyncRunner.request(refreshUrl, parameters, new RefreshListener(), null );
   }
Run Code Online (Sandbox Code Playgroud)

这是我的RefreshListener版本......

  //REFRESH LISTENER
    public class RefreshListener extends BaseRequestListener {

        public void onComplete(final String response, Object state) {


            try { …
Run Code Online (Sandbox Code Playgroud)

android facebook facebook-android-sdk facebook-access-token

8
推荐指数
1
解决办法
3304
查看次数

Facebook 60天访问令牌和不推荐使用的Offline_Access

Facebook的"弃用脱机访问"文档(http://developers.facebook.com/docs/offline-access-deprecation/)声明如下:


*服务器端OAuth开发人员

如果access_token是从服务器端 OAuth调用生成的,则生成的access_token将具有更长的到期时间.如果在该用户仍然存在有效的access_token的情况下进行呼叫,则来自该第二次呼叫的返回的access_token可以是相同的或者可能已经改变,但是在任何一种情况下,到期时间都将被重置.同样,在同一天多次调用此选项将仅导致第一次调用延长到期时间.*


这似乎意味着服务器端OAuth 自动获得一个长期到期令牌.如果我在Facebook Developer高级对话框中启用"弃用脱机访问"设置,我确实会发现这种情况 - 令牌在60天后到期.但随着设置,令牌将在2小时后到期.

关于这个设置,我有点困惑:

题:

  • 这个设置听起来像是一个"过渡/迁移"选项....如果我启用此选项,我将在6个月后获得60天代币吗?不使用"交换"端点?

  • 为什么不自动将所有令牌设置为60天?

facebook facebook-graph-api facebook-c#-sdk facebook-oauth

7
推荐指数
1
解决办法
8659
查看次数