footprint blog
footprint blog

Reputation: 13

I got 404 Error from Google API's via servlet in GAE, but got correct response via browser

I can get correct response from Google API's via web browser. It is say, When I access to https://www.googleapis.com/blogger/v3/blogs/4871538073781423026?access_token=XXXXXXXX by some web browser, then get correct response like

{
 "kind": "blogger#blog",
 "id": "4871538073781423026",
 "name": "SoffeeShop",
 "description": "",
 "published": "2012-10-24T23:55:32+09:00",
 "updated": "2015-03-04T14:31:00+09:00",
 "url": "http://soffeeshop.blogspot.com/",
 "selfLink": "https://www.googleapis.com/blogger/v3/blogs/4871538073781423026",
 "posts": {
  "totalItems": 58,
  "selfLink": "https://www.googleapis.com/blogger/v3/blogs/4871538073781423026/posts"
 },
 "pages": {
  "totalItems": 0,
  "selfLink": "https://www.googleapis.com/blogger/v3/blogs/4871538073781423026/pages"
 },
 "locale": {
  "language": "en",
  "country": "",
  "variant": ""
 }
}

Although, when I do REST with servlet in GAE, like

URL url = new URL("https://www.googleapis.com/blogger/v3/blogs/4871538073781423026?access_token=XXXXXXXXX");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("X-Appengine-Inbound-Appid", "XXXXX");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Host", "googleapis.com");

or

URL url = new URL("https://www.googleapis.com/blogger/v3/blogs/4871538073781423026);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Authorization", "Bearer " + access_token); 
connection.setRequestProperty("X-Appengine-Inbound-Appid", "XXXXX");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Host", "googleapis.com");

i just got "404 Not Found" Error.

I could get access_token with OAuth2 using same HttpURLConnection in the same servlet in GAE, I could not do access to just Google API's. So, it's mean Http Connections are working well to access to other servers, but it looks like that Google API's deny access from servlet in GAE.

How to access Google API's or Blogger API via servlet in GAE? Please help me.

Upvotes: 1

Views: 104

Answers (2)

Shobhit
Shobhit

Reputation: 488

Did you provide the permission to your GAE app to access the Blogger API. I think when you Generate the clientId in your developer console of your app, you have to provide the name of your App in the redirect URIS as http://app-id.appspot.com. i think it will resolve your issue.

Upvotes: 0

Harsh kurra
Harsh kurra

Reputation: 1216

You may need to enable blogger API in your GAE project from google developer console it may ask you some question like "how you would like to use the Blogger API?".

Upvotes: 1

Related Questions