0
https://developers.google.com/accounts/docs/OAuth2InstalledApp

次のリンクを使用して、WebビューでGoogleアカウントにサインアップするようにユーザーに提供しています

webview.loadUrl("https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&state=%2F&response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob&client_id=706645665586.apps.googleusercontent.com");

これには、Google APIコンソールで指定されたクライアントIDとリダイレクトURIが含まれています。つまり、リダイレクトURIの選択 https://developers.google.com/accounts/docs/OAuth2InstalledApp

最後に、view.getTitle()を使用して、ブラウザのタイトルバーに返される認証コードを取得します。

その後、送信するには別のリクエストが必要です。実際のリクエストは次のようになります。

POST /o/oauth2/token HTTP/1.1
Host: accounts.google.com
Content-Type: application/x-www-form-urlencoded
code=4/y_jtre05wvb6QSPo0Tkx5AbLfWB
client_id=706645665586.apps.googleusercontent.com
client_secret={client_secret}&
redirect_uri=urn:ietf:wg:oauth:2.0:oob
grant_type=authorization_code

だから今HTTPPOSTリクエストをしている間..

    DefaultHttpClient httpcl = new DefaultHttpClient();
    HttpPost httpp = new HttpPost("https://accounts.google.com/o/oauth2/auth");
    List<NameValuePair> a = new ArrayList<NameValuePair>();
    a.add(new BasicNameValuePair("code", "4/y_jtre05wvb6QSPo0Tkx5AbLfWB"));
    a.add(new BasicNameValuePair("client_id", "706645665586.apps.googleusercontent.com"));
    try {
        StringEntity mEntity = new StringEntity("");
        mEntity.setContentType(" application/x-www-form-urlencoded");
        httpp.setEntity(mEntity);
        httpp.setEntity(new UrlEncodedFormEntity(a));
        HttpResponse response1 = httpcl.execute(httpp);

        String response = EntityUtils.toString(response1.getEntity());
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

だから私は悪いトークンの応答を得ています...私は昨日からこれを試していますそして提案と助けをいただければ幸いです..私の主な目的はAndroidのGmailアカウントを使用してユーザー情報を取得することです

4

2 に答える 2

1

ここでさまざまなフローを少し混ぜていると思います:

  • クライアント側のフローでは クライアント シークレットは必要ありませんが、主に Javascript アプリケーション用です。
  • ただし、インストール済みアプリケーション フローには クライアント シークレット必要です。

    登録時に取得した client_id と client_secret は、アプリケーションのソース コードに埋め込まれます。このコンテキストでは、client_secret は明らかにシークレットとして扱われません。

    おそらく、 Installed application -> AndroidAPI コンソールクライアント IDを生成したため、クライアント IDのみを取得し、アプリケーションの証明書のフィンガープリントを指定する必要がありました。このタイプのクライアント IDは、最近リリースされ、推奨されている (安全性が高いため) Google Play Servicesで使用するためのものです。

    インストール済みアプリケーション フローを手動で使用する場合は、インストール済みアプリケーション -> その他のクライアント IDを生成する必要があります。ここで、クライアント シークレットも取得します。アクセス トークンの認証コードを交換する場合、5 つのパラメーターすべてを指定する必要があります。

    code            The authorization code returned from the initial request
    client_id       The client_id obtained during application registration
    client_secret   The client secret obtained during application registration
    redirect_uri    The URI registered with the application
    grant_type      As defined in the OAuth 2.0 specification, this field must contain a value of authorization_code
    
于 2012-09-28T08:44:15.793 に答える
0

私はついに動作するサンプルを見つけました。Google+開発者APIを使用できます。githubでこのプロジェクトとこの記事を見てください。ここ

于 2012-12-24T10:18:54.757 に答える