是否可以在Android应用中使用extendAccessTokenIfNeeded来扩展Facebook令牌? [英] Is it possible to extend Facebook tokens with extendAccessTokenIfNeeded in an Android app?

查看:135
本文介绍了是否可以在Android应用中使用extendAccessTokenIfNeeded来扩展Facebook令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这可能会影响很多Facebook / Android开发人员,但似乎没有太多的讨论话题...



我的问题



有没有人使用extendAccessTokenIfNeeded函数成功刷新了一个令牌?如果您确实有成功,该设备(或仿真器)运行的版本是什么?



背景 p>

我从Facebook收到一封电子邮件,说offline_access权限将从2012年5月1日起不再适用,Facebook推荐升级到最新的SDK。



我升级到最新的SDK,官方的Facebook应用程序安装在我的设备上,(最终!)单点登录似乎工作正常。我收到了60天的令牌,这再一次可以。



当我尝试使用extendAccessTokenIfNeeded(Context context,ServiceListener serviceListener)时,问题开始了。我无法让它刷新我的令牌更长的到期时间。我等待24小时尝试,但令牌不会刷新。我可以获得更新令牌的唯一方法是注销并登录。当我使用示例项目Hackbook时,这也发生了。



最明显的答案是我做错了,但是,一个错误报告已提交给Facebook说,shouldExtendAccessToken几乎总是返回false。



extendAccessTokenAsNeeded()的替代方案

关于offline_access弃用的Facebook文档令牌可以扩展使用Graph API。但是,这具有需要App Secret的缺点被包含在URL中。一个优点是用户不需要在他们的设备上安装官方的Facebook应用程序。



其他想法和疑虑




  • 通过在Facebook.java中更改extendAccessTokenIfNeeded函数始终返回true,我想我有一次刷新。 (我所说的想的原因是因为它不会重复这个行为,我怀疑我必须等待24小时才能再次成功)


  • 我注意到Hackbook要求 AndroidHttpClient
    进口。这仅适用于API 8。这是否意味着
    ,Facebook SSO(特别是令牌刷新)仅适用于具有API 8及更高版本的设备?


  • Facebook。 SDK中包含的apk 很旧。也许这就是为什么令牌不会刷新运行API 8及更高版本的模拟器?


  • 最后,所有这些只涉及那些有
    安装官方的Facebook应用!另一种方法需要为没有官方Facebook应用程序的用户完成(只是抱怨!)




相关的Facebook链接



GitHub上的Facebook-Android-SDK



Facebook Android教程



Facebook offline_access权限弃用



Facebook错误报告



相关堆栈溢出问题 p>

Facebook 60天访问令牌和Deprecated Offline_Access



Facebook访问令牌无法扩展



在5月1日之后,offline_access如何被淘汰之后?



无法扩展Facebook访问令牌



保护应用程式的秘密对于extendAccessToken使用(Java / Android)

解决方案

我不知道Android开发,但如果你有这个功能的问题,也许有一个类似的功能,CURL在Android中将al低你叫
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



(Google透露: http://thesoftwarerogue.blogspot.com/2010/05/porting-of-libcurl-to-android-os- using.html 了解如何使用CURL从Android)


I think this might effect a lot of Facebook/Android developers and yet there does not seem to be that much discussion on the topic...

My question

Has anyone successfully refreshed a token using the extendAccessTokenIfNeeded function? If you did have success, what version was the device (or emulator) running?

Background

I received an email from Facebook saying the offline_access permission will be deprecated from May 1st 2012 and Facebook recommended upgrading to their latest SDK. Fine.

I upgraded to the latest SDK, the official Facebook app is installed on my device and (eventually!) Single Sign On seems to be working OK. I am receiving 60 day tokens which again is OK.

Problems started when I tried to use extendAccessTokenIfNeeded(Context context, ServiceListener serviceListener). I could not get it to refresh my tokens for a longer expiry time. I waited 24 hours between attempts but the token would not refresh. The only way I can get a refreshed token is to log out and login. This also happened when I used the example project "Hackbook".

The most obvious answer is that I am doing something wrong, but, a bug report was submitted to Facebook saying that... "shouldExtendAccessToken will practically almost always return false." This report has been given the priority "wishlist".

Alternatives to the extendAccessTokenAsNeeded()

In the Facebook documentation about offline_access deprecation tokens can be extended using the Graph API. However this has the disadvantage of needing the "App Secret" being included in the URL. An advantage is that the user would not need to have the official Facebook app installed on their device.

Other ideas and concerns

  • By changing the extendAccessTokenIfNeeded function in Facebook.java to always return true, I think I got it to refresh once. (The reason I say "think" is because it won't repeat the behaviour and I suspect I have to wait another 24 hours before any chance of another success)

  • I notice that Hackbook requires AndroidHttpClient to be imported. This is only available for API 8 onwards. Does this mean that Facebook SSO (in particular token refreshing) is only likely to work on devices with API 8 and later?

  • The Facebook.apk included in the SDK is quite old. Perhaps this is why the tokens don't refresh on emulators running API 8 and later?

  • And lastly, all of this only relates to those people that have the official Facebook app installed! Another method needs to be completed for those people without the official Facebook app (just complaining now!)

Relevant Facebook links

Facebook-Android-SDK at GitHub

Facebook Android Tutorial

Facebook offline_access permission deprecation

Facebook bug report

Related Stack Overflow Questions

Facebook 60 day access token and Deprecated Offline_Access

Facebook access token can not be extended

How would offline_access work after deprecation after May 1st?

Facebook access token can not be extended

Protecting app secret for extendAccessToken usage (Java/Android)

解决方案

I don't know Android development, but if you're having issues with that function, maybe there's a similar function of CURL within Android that will allow you to call 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

(google revealed: http://thesoftwarerogue.blogspot.com/2010/05/porting-of-libcurl-to-android-os-using.html on how to CURL from Android)

这篇关于是否可以在Android应用中使用extendAccessTokenIfNeeded来扩展Facebook令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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