1

そこで、Twitter ストリーミング API を試すことにしたので、Twitter 開発ページにアクセスして、oAuth トークンを生成するテスト アプリケーションを作成し、ターミナルで curl コマンドを使用して試してみたところ、ストリームがちょうど入ってきました。結構ですが、問題に直面した場所で同じことを行うために、Javaスニペットの小さな部分を書き込もうとすることにしました。

以下は私のコードです。トークンと認証コードは、実際のものではなく * で記述して削除しました。

public final static void main(String[] args) throws Exception {

    HttpClient httpclient = new DefaultHttpClient();

    try {
        HttpPost post = new HttpPost(
                "https://stream.twitter.com/1/statuses/sample.json");
        final String header = "OAuth oauth_consumer_key=\"********\", oauth_nonce=\"*******", oauth_signature=\"**************", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1339160825\", oauth_token=\"*********", oauth_version=\"1.0\"";
        final String headerTitle = "Authorization";
        post.addHeader(headerTitle, header);
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = httpclient.execute(post, responseHandler);
        System.out.println("----------------------------------------");
        System.out.println(responseBody);
        System.out.println("----------------------------------------");
    } catch (HttpResponseException e) {
        System.out.println("Reponse status code: " + e.getStatusCode()
                + "\n");
        e.printStackTrace();
        httpclient.getConnectionManager().shutdown();
    }
}

インポート行も削除しました。

401 応答が返され続けます。ヘッダーに問題がある可能性があります。

前もって感謝します。

4

0 に答える 0