我需要獲取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