これは私の URL 投稿です。
String urlParameters = "&consumer_key="+AppSession.getPocketConsumerKey()+"&client_secret="+AppSession.getPocketRedirectUri();
String request = "https://getpocket.com/v3/oauth/request";
URL url;
try {
url = new URL(request);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("charset", "utf-8");
connection.setRequestProperty("X-Accept","application/x-www-form-urlencoded");
connection.setUseCaches (false);
connection.connect();
DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
wr.writeBytes(urlParameters);
Log.d("urlparmas",urlParameters);
wr.flush();
wr.close();
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response = new StringBuffer();
while((line = rd.readLine()) != null) {
response.append(line);
response.append('\r');
}
rd.close();
Log.d( "response",response.toString());
} catch (Exception e) {
e.printStackTrace();
}
私のリダイレクト URI: MyApp://callback
<activity android:name="com.app.account.Register" android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="MyApp" android:host="callback"/>
</intent-filter>
</activity>
そのため、コールバック URL から応答がありません。コードのどこが間違っているのだろうか。
編集:
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response = new StringBuffer();
while((line = rd.readLine()) != null) {
response.append(line);
response.append('\r');
}
rd.close();
Log.d( "response",response.toString());
これにより、エラーが発生します。