我想使用以下代码访问 twitch api。
package droa.app.twitch;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.util.ArrayList;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
public class Notifier {
/**
* @param args
* @throws URISyntaxException
* @throws IOException
* @throws ClientProtocolException
*/
public static void main(String[] args) throws URISyntaxException, ClientProtocolException, IOException {
HttpPost request = new HttpPost("https://api.twitch.tv/kraken/oauth2/token");
org.apache.http.client.HttpClient client = new DefaultHttpClient();
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("grant_type", "password"));
postParameters.add(new BasicNameValuePair("client_id", Credentials.clientid));
postParameters.add(new BasicNameValuePair("client_secret", Credentials.clientsecret));
postParameters.add(new BasicNameValuePair("username", Credentials.username));
postParameters.add(new BasicNameValuePair("password", Credentials.password));
postParameters.add(new BasicNameValuePair("scope", "user_read"));
request.setEntity(new UrlEncodedFormEntity(postParameters));
HttpResponse httpResponse = client.execute(request);
BufferedReader rd = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
}
}
但它似乎不起作用,我得到一个错误。
{"status":403,"message":"客户端 ID chodustnuqjzkc07ohd3rfkbzrlopzb","error":"Forbidden"}
我遵循了https://github.com/justintv/Twitch-API/blob/master/password-credentials.md上的官方指南
我想知道,我做错了什么?