我需要获取OAuth2身份验证令牌才能将其传递到服务器,以便它可以为用户提取Google阅读器订阅源列表。服务器是.NET - 我无法访问它或它的代码,但最有可能的是它使用unofficial Reader APIAndroid - 无法使用OAuth访问令牌检索Google阅读器订阅源
我能够使用Android帐户管理器获取有效的令牌用于此目的使用以下代码(请注意,authTokenType = “读者”)
Account account = accounts[0];
manager.getAuthToken(account, "reader", null, this, new AccountManagerCallback<Bundle>() {
public void run(AccountManagerFuture<Bundle> future) {
try {
// If the user has authorized your application to use the tasks API
// a token is available.
String token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN);
// Now you can send the token to API...
cacheManager.putString(GOOGLE_AUTH, token);
GoogleReaderManager.startAddFeedActivity(AddGoogleReaderSourcesActivity.this);
finish();
} catch (OperationCanceledException e) {
Log.e(TAG, "User cancelled", e);
finish();
} catch (Exception e) {
Log.e(TAG, "Failed to obtain Google reader API_KEY", e);
}
}
}, null);
当我发送令牌到服务器端.net应用程序上面的代码工作正常:应用程序能够检索的读者订阅列表。
问题是,这只适用于“Google内部”设备。在努克,我没有这样的运气,因为我无法找到将Google帐户添加到客户经理的方式。所以我试图使用OAuth 2协议作为described here
只要获得令牌,它就可以正常工作:用户从移动页面中批准应用,该页面返回代码令牌,然后移动应用交换Auth令牌。但是,此令牌不适用于服务器进程。我有,也许我使用了错误的范围在此URL的感觉:
作用域,我曾尝试各种组合:
- https://www.google.com/reader/api
- https://www.google.com/reader/api/0
- https://www.google.com/reader/api/0/subscription/list
- https://www.google.com/reader/api+https://www.google.com/reader/atom
这里是JSON的例子是从获得令牌POST
{"expires_in":3600,
"token_type":"Bearer",
"access_token":"ya29.AHES6ZSEvuUb6Bvd2DNoMnnN_UnfxirZmf_RQjn7LptFLfI",
"refresh_token":"1\/bUwa5MyOtP6VyWqaIEKgfPh08LNdawJ5Qxz6-qZrHg0"}
上午我搞乱范围或令牌类型退换吗?不知道如何更改令牌类型。任何其他想法?
P.S.谷歌帐户登录页面要求:Manage your data in Google Reader
,这就是为什么我怀疑范围是错误的
如此处所述,范围应为'https://www.google.com/reader/api/'。消除中间人:尝试直接访问API,并且当它启动时,然后使用.NET服务器。读者身份验证:http://code.google.com/p/google-reader-api/wiki/Authentication – 2012-04-23 01:57:48
这是我尝试的第一个范围,唉,不行。 – Bostone 2012-04-23 04:47:50