Google+ API的GoogleJsonResponseException

时间:2017-07-25 20:49:30

标签: java android google-plus

在我的Android应用程序中,我集成了Google+ API,我已经验证了访问权限和范围。我想在我的Android应用程序中插入注释和新帖子。我将Post方法与google文档集成在一起。引用为https://developers.google.com/+/domains/posts/creating

MainActivity.java

   //Set the accesstoken
         GoogleCredential credential = new 
  GoogleCredential().setAccessToken( token );

    // Create a list of ACL entries
            PlusDomainsAclentryResource resource = new PlusDomainsAclentryResource();
            resource.setType("domain"); // Share to domain
            List<PlusDomainsAclentryResource> aclEntries =
                    new ArrayList<PlusDomainsAclentryResource>();
            aclEntries.add(resource);

            Acl acl = new Acl();
            acl.setItems(aclEntries);
            acl.setDomainRestricted(true);  // Required, this does the domain restriction

  // Create a new activity object
            com.google.api.services.plusDomains.model.Activity   activity = new com.google.api.services.plusDomains.model.Activity()
                    .setObject(new com.google.api.services.plusDomains.model.Activity.PlusDomainsObject().setOriginalContent(comments))
                    .setAccess(acl);
//Execute the API
            com.google.api.services.plusDomains.model.Activity plusDomains = new PlusDomains(common.HTTP_TRANSPORT, common.JSON_FACTORY, credential ).activities().insert("me",activity)
                    .execute();

我得到了以下错误。我参考以下链接,但不是它不工作

Google coordinate authentication

com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 
Unauthorized
W/System.err: {
W/System.err:   "code" : 401,
W/System.err:   "errors" : [ {
W/System.err:     "domain" : "global",
W/System.err:     "location" : "Authorization",
W/System.err:     "locationType" : "header",
W/System.err:     "message" : "Invalid Credentials",
W/System.err:     "reason" : "authError"
W/System.err:   } ],
 W/System.err:   "message" : "Invalid Credentials"
W/System.err: }

0 个答案:

没有答案