1

OAuth2 認証トークンを取得してサーバーに渡し、ユーザーの Google リーダー フィードのリストを取得できるようにする必要があります。サーバーは .NET です - 私はそれにもそのコードにもアクセスできませんが、非公式の Reader APIを使用している可能性が高いです

Android アカウント マネージャーを使用して、次のコードでこの目的に有効なトークンを取得できました (authTokenType="reader" に注意してください)。

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 内部」デバイスでのみ機能することです。Nook では、Google アカウントをアカウント マネージャーに追加する方法を見つけることができなかったため、そのような運はありませんでした。ここで説明されているように、OAuth 2プロトコルを使用して試みています

トークンを取得する限りは正常に機能します。ユーザーはモバイル ページからアプリを承認し、コード トークンを返します。コード トークンは、モバイル アプリが Auth トークンと交換します。ただし、このトークンはサーバー プロセスでは機能しません。この URL で間違ったスコープを使用している可能性があります。

https://accounts.google.com/o/oauth2/auth?response_type=code&scope=https://www.google.com/reader/api/0/subscription/list&redirect_uri=http://localhost&approval_prompt=force&state=/ok&client_id = {apps.client.id}

さまざまな組み合わせで試したスコープ:

  1. https://www.google.com/reader/api
  2. https://www.google.com/reader/api/0
  3. https://www.google.com/reader/api/0/subscription/list
  4. https://www.google.com/reader/api+https://www.google.com/reader/atom

get token POST から返される JSON の例を次に示します。

{"expires_in":3600,
     "token_type":"Bearer",
     "access_token":"ya29.AHES6ZSEvuUb6Bvd2DNoMnnN_UnfxirZmf_RQjn7LptFLfI",
     "refresh_token":"1\/bUwa5MyOtP6VyWqaIEKgfPh08LNdawJ5Qxz6-qZrHg0"}

スコープやトークンの種類を台無しにしていませんか? トークンの種類を変更する方法がわかりません。他のアイデアはありますか?

PS Google アカウントのログイン ページで次Manage your data in Google Readerのように尋ねられます:

4

1 に答える 1

0

https://www.google.com/reader/api/0/subscription/listで動作しました。だからあなたと共有することを考えました。

私は有効ですaccess_token

これは私がそれを解決しようとしたものです(部分的に):

  • GoogleはOAuth2.oプレイグラウンドを提供しています。ここでは、OAuth 2.0のすべての側面と、データをフェッチするための最終的なAPI呼び出しを実際にシミュレートします。これは、リクエストに送信されているものを明確に示しているため、非常に役立ちました。URLは次のとおりです:https ://developers.google.com/oauthplayground/
  • これを使用して、以下のAPI呼び出しを微調整しましたが、機能します:)

    public static  String getReaderContent(String accessToken){
       String url = "https://www.google.com/reader/api/0/subscription/list" ; 
    
       HttpClient client = new HttpClient();
    
       GetMethod method = new GetMethod(url);
       String response="";
       method.setRequestHeader("Authorization", "OAuth "+accessToken);
       try {
         int statusCode = client.executeMethod(method);
         String response= method.getResponseBodyAsString();
    
         System.out.println("response " + responseStr);
       } catch (HttpException e) {
         e.printStackTrace();
       } catch (IOException e) {
        e.printStackTrace();
      }
    return response;
    }
    

したがって、これはサブスクリプションリストを取得するために適切に機能します。しかし、あなたがあなたの質問で言及したリーダーAPIのためにそれを機能させることができませんでした。

あなたがグーグルリーダーAPIを回避する方法を持っているかどうか私に知らせてください。

于 2013-02-19T06:41:21.983 に答える