Blogger Java API Code Formation Issues
Kareem Glover <[email protected]>
| Newsgroups | gmane.comp.web.blogger.api |
|---|---|
| Message-ID | <[email protected]> |
I am able to complete this request via the cloud console but having trouble
forming the correct statement in Java. I am getting a 401 Authorization
error. I am using the Google APP Engine. Any ideas on where I may be going
wrong. I tried numerous things over the weekend and decided to reach out to
the blog.
Thanks.
-- Request Via Cloud Console
Request
GET https://www.googleapis.com/blogger/v3/blogs/7676001971884966148/posts?key={YOUR_API_KEY}
Authorization: Bearer ya29.1.AADtN_Vd7lKj8Xy3KbZ1veJjjjv712Nc1erLY2dmAK3gorNilVd0652vnqrrovfuLfSKkQ
X-JavaScript-User-Agent: Google APIs Explorer
Response
200 OK
- Show headers -
{
"kind": "blogger#postList",
"nextPageToken": "CgkIChjim-ftqygQhIKb6_zjqMNq",
"items": [
{
etc.....
[code]
> public class BloggerHandler
> {
> public static final Logger log =
> Logger.getLogger(BloggerHandler.class.getName());
>
> public void testCreds() throws Exception {
> try{
> ArrayList<String> scopes = new ArrayList<String>();
> scopes.add("https://www.googleapis.com/auth/blogger");
> scopes.add("https://www.googleapis.com/auth/blogger.readonly");
>
>
> AppIdentityService appIdentity =
> AppIdentityServiceFactory.getAppIdentityService();
> AppIdentityService.GetAccessTokenResult accessToken =
> appIdentity.getAccessToken(scopes);
> // The token asserts the identity reported by
> appIdentity.getServiceAccountName()
> JSONObject request = new JSONObject();
> //request.put("maxPosts", "1");
> //request.put("view", "AUTHOR");
> log.info("request!!!" + request);
> URL url = new
> URL("https://www.googleapis.com/blogger/v3/blogs/7676001971884966148/posts?");
> log.info("URL:" + url);
> HttpURLConnection connection = (HttpURLConnection)
> url.openConnection();
> connection.setDoOutput(true);
> connection.setRequestMethod("GET");
> connection.addRequestProperty("Content-Type", "application/json");
> connection.addRequestProperty("Authorization", "OAuth" +
> accessToken.getAccessToken());
>
> log.info("Con!!" + connection);
>
> OutputStreamWriter writer = new
> OutputStreamWriter(connection.getOutputStream());
> request.write(writer);
> writer.close();
> log.info("connection:" + connection.getResponseCode());
> if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
> // Note: Should check the content-encoding.
> JSONTokener response_tokens = new
> JSONTokener(connection.getInputStream());
> JSONObject response = new JSONObject(response_tokens);
>
> log.info("resp:" + response.get("title"));
>
>
>
> } // end if
>
> else {
> throw new Exception();
> }// end else
>
> } // end try
>
> catch (Exception e) {
> // Error handling elided.
> log.info("ex:" + e);
>
>
> }
> // end catch
>
>
> }// end void
>
> }// end class
// AP Engine Logs
1. 2013-12-08 21:52:13.033
2. 2013-12-08 21:52:13.105 /rssparser 200 961ms 0kb Mozilla/5.0 (Windows
NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63
Safari/537.36 module=default version=1
174.99.72.235 - - [08/Dec/2013:18:52:13 -0800] "GET /rssparser HTTP/1.1" 200 0 - "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36" "thepepperbird.appspot.com" ms=961 cpu_ms=175 cpm_usd=0.000020 app_engine_release=1.8.8 instance=00c61b117cc2c6a3fcf60ecdad05a68acf4606 <https://appengine.google.com/instances?app_id=s~thepepperbird&version_id=1.372201475795269505&key=00c61b117cc2c6a3fcf60ecdad05a68acf4606#00c61b117cc2c6a3fcf60ecdad05a68acf4606>
3. I2013-12-08 21:52:12.924
com.thepepperbird.appengine.BloggerHandler testCreds: request!!!{}
4. I2013-12-08 21:52:12.926
com.thepepperbird.appengine.BloggerHandler testCreds: URL:https://www.googleapis.com/blogger/v3/blogs/7676001971884966148/posts?
5. I2013-12-08 21:52:13.003
com.thepepperbird.appengine.BloggerHandler testCreds: Con!!com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection:https://www.googleapis.com/blogger/v3/blogs/7676001971884966148/posts?
6. I
com.thepepperbird.appengine.BloggerHandler testCreds: connection:401
7. I2013-12-08 21:52:13.034
com.thepepperbird.appengine.BloggerHandler testCreds: ex:java.lang.Exception
--
You received this message because you are subscribed to the Google Groups "Blogger Developer Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/bloggerdev.
For more options, visit https://groups.google.com/groups/opt_out.