1

AndroidとのGoogleバズAPI統合を実装しています。OAuth を正常に処理し、AccessToken を取得しました。しかし、Buzz でメッセージを POST しようとすると、ステータス 401 で以下の応答が返されます。

{"error":{"errors":[{"domain":"global","re​​ason":"invalid","message":"Token invalid - Invalid AuthSub token.","locationType":"header", "location":"Authorization"}],"code":401,"message":"トークンが無効です - AuthSub トークンが無効です。"}}

私は oAuth に singpost ライブラリを使用しました。以下は、メッセージを BUZZ に投稿するために使用しているコードです。

String serurl = "https://www.googleapis.com/buzz/v1/activities/@me/@self?key=@@KEY&alt=json";

serurl = serurl.replace("@@KEY", AppSettings.GOOGLE_API_KEY);

CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(
                    AppSettings.GOOGLE_CONSUMER_KEY,
                    AppSettings.GOOGLE_CONSUMER_SECRET);
consumer.setMessageSigner(new HmacSha1MessageSigner());
consumer.setTokenWithSecret(destination.AccessToken,
                    destination.AccessTokenSecret);

String bstr = "{\"data\": {\"object\": {\"type\": \"note\",\"content\": \""
                + msg + "\"}}}";

HttpClient client = new DefaultHttpClient();

HttpPost method = new HttpPost(consumer.sign(serurl));

method.setHeader("Content-Type", "application/json");
method.addHeader("Accept", "application/json");

method.addHeader("Authorization", URLEncoder.encode(destination.AccessToken));


method.setEntity(new StringEntity(bstr, "UTF-8"));


HttpResponse response = client.execute(method);

final HttpEntity entity = response.getEntity();
String responseString = "";
if (entity != null) {
    InputStream inputStream = null;
    try {
         inputStream = entity.getContent();
          responseString = Utils.convertinputStreamToString(new Utils.FlushedInputStream(
                                    inputStream));
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
            entity.consumeContent();
        }
    }
}
    System.out.println(responseString);

そして、私はこの応答を得ています:

{"error":{"errors":[{"domain":"global","reason":"invalid","message":"Token invalid - Invalid AuthSub token.","locationType":"header","location":"Authorization"}],"code":401,"message":"Token invalid - Invalid AuthSub token."}}

それについて私を助けることができる人はここにいますか?

ありがとう。

4

0 に答える 0