Hello Tim,
I am listing the complete code below (using the Web Application approach only);
public class TestSubscription {
private final static String GOOGLE_CLIENT_ID = "myclientid";
private final static String GOOGLE_CLIENT_SECRET = "client_secret";
private final static String CODE = "code";
public static void main(String[] args) {
HttpClient client = new DefaultHttpClient();
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5);
nameValuePairs.add(new BasicNameValuePair("grant_type",
"authorization_code"));
nameValuePairs.add(new BasicNameValuePair("client_id",
GOOGLE_CLIENT_ID));
nameValuePairs.add(new BasicNameValuePair("client_secret",
GOOGLE_CLIENT_SECRET));
nameValuePairs.add(new BasicNameValuePair("code", CODE));
nameValuePairs.add(new BasicNameValuePair("redirect_uri",
GOOGLE_REDIRECT_URI));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
org.apache.http.HttpResponse response = client.execute(post);
BufferedReader reader = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
StringBuffer buffer = new StringBuffer();
for (String line = reader.readLine(); line != null; line = reader
.readLine()) {
buffer.append(line);
}
JSONObject json = new JSONObject(buffer.toString());
String refreshToken = json.getString("refresh_token");
} catch (Exception e) {
e.printStackTrace();
}
}
}
When I print the headers of HttpResponse object response, I get the following;
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Mon, 29 Oct 2012 03:58:54 GMT
Content-Type: application/json
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Transfer-Encoding: chunked
I can't figure out where I am going wrong.
- UKSDroid