そのため、現在、Twitter の 1.1 Application-only-authを使用して、特定のユーザーからツイートを取得する Android アプリを作成しています。これには、ベアラー トークンを取得するために POST HTTP 要求が必要です。HttpsURLConnection
を使用して接続を開くメソッドを設定していますが、
conn.setDoOutput(true);
メソッドが機能していませんconn.doOutput
とどまるfalse
- リクエストはデフォルトのままです
GET
。
私は何か間違ったことをしていますか?
このメソッドはAsyncTask
のメソッドで呼び出されdoInBackground()
ます。
public String getRequestBearerToken(String endUrl) throws IOException {
String encodedCred = encodeKeys("API-key", "API-secret");
HttpsURLConnection connection = null;
try {
URL url = new URL(endUrl);
connection = (HttpsURLConnection) url.openConnection();
connection.setInstanceFollowRedirects(false);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
// POST request properties
connection.setRequestProperty("Host", "api.twitter.com");
connection.setRequestProperty("User-Agent", getResources()
.getString(R.string.app_name));
connection.setRequestProperty("Authorization", "Basic "
+ encodedCred);
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded;charset=UTF-8");
connection.setRequestProperty("Content-Length", "29");
connection.setUseCaches(false);
...