I try to program a APP for WoW Requests. I am new in API programming. First I request the authCode which I need to request my token. I would like to understand how can I get this Token. I read that I require a HTTP Client:
"This CURL command converts an authorization code into an access token for calling APIs on behalf of the client application and authenticated user (requires HTTP client)"
I think that I missunderstand the Token request.
But I get an Error:
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
W/System.err: android.os.NetworkOnMainThreadException
W/System.err: at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1565)
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:115)
W/System.err: at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
at java.net.InetAddress.getAllByName(InetAddress.java:1152)
at com.android.okhttp.Dns$1.lookup(Dns.java:41)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:178)
at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:144)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:86)
at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:176)
W/System.err: at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:128)
at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:97)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:289)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:232)
W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:465)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:542)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:106)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:30)
at de.codeyourapp.battlenet.MainActivity.test(MainActivity.java:111)
at de.codeyourapp.battlenet.MainActivity.onResume(MainActivity.java:86)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1446)
FUNCTION:
public void test(){
HttpURLConnection connection = null;
try {
URL url = new URL ("https://(REGION)battle.net/oauth/token");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
line111!!!! connection.setRequestProperty ("Authorization", "Basic " + (CLIENTID+ ":" + SECURE).getBytes("UTF-8"));
// connection.getOutputStream().write(("&redirect_uri=...&scope=...???&grant_type=authorization_code&code=" + AUTHCODE).getBytes("UTF-8"));
int rc = connection.getResponseCode();
System.out.println(rc);
InputStream content = (InputStream)connection.getInputStream();
BufferedReader in = new BufferedReader (new InputStreamReader(content));
String line = in.readLine();
while(line != null){
System.out.println(line);
line = in.readLine();
}
}
My Request have to look like this:
curl -X POST https://(region).battle.net/oauth/token
-u <developer client id>:<developer secret>
-d redirect_uri=<redirect URI used in authorize request>
-d scope=<space separated scopes>
-d grant_type=authorization_code
-d code=<authorization code>
I need only the Token to do make requests. Can someone help me pls? :)