Google plus 通过google plus域API创建新帖子

Google plus 通过google plus域API创建新帖子,google-plus,google-plus-domains,Google Plus,Google Plus Domains,我试图从我自己的CMS中创建一个到Google plus的自动帖子。我已经尝试过Google Plus域API。但是,尽管我设置了正确的范围,并且在我的凭证上设置了权限,但我总是得到禁止日志 这是我的密码 @RequestMapping(value = { "/callback" }, method = RequestMethod.GET) public String gplusCallback ( @RequestParam(value = "code", required =

我试图从我自己的CMS中创建一个到Google plus的自动帖子。我已经尝试过Google Plus域API。但是,尽管我设置了正确的范围,并且在我的凭证上设置了权限,但我总是得到禁止日志

这是我的密码

@RequestMapping(value = { "/callback" }, method = RequestMethod.GET)
public String gplusCallback (
        @RequestParam(value = "code", required = false) String code,
        WebRequest webRequest, 
        HttpServletRequest request,
        HttpServletResponse response, 
        HttpSession session) throws GeneralSecurityException, IOException {

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            new NetHttpTransport(),
            new JacksonFactory(),
            CLIENT_ID, 
            CLIENT_SECRET,
            SCOPE)
            .setApprovalPrompt("force")
            .setAccessType("offline").build();

    System.out.println("Codenya " + code);
    GoogleTokenResponse tokenResponse = flow.newTokenRequest(code)
            .setRedirectUri(REDIRECT_URI).execute();
    GoogleCredential credential = new GoogleCredential.Builder()
        .setTransport(new NetHttpTransport())
        .setJsonFactory(new JacksonFactory())
          .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
          .setServiceAccountScopes(SCOPE)
          .setServiceAccountUser(USER_EMAIL)
          .setServiceAccountPrivateKeyFromP12File(
              new java.io.File(SERVICE_ACCOUNT_PKCS12_FILE_PATH))
          .build();


    Plus service = new Plus.Builder(new NetHttpTransport(), new JacksonFactory(), credential)
            .setApplicationName("GNEWS.ID")
            .build();
    com.google.api.services.plus.model.Person mePerson = service.people().get("me").execute();

    System.out.println("ID:\t" + mePerson.getId());
    System.out.println("Display Name:\t" + mePerson.getDisplayName());
    System.out.println("Image URL:\t" + mePerson.getImage().getUrl());
    System.out.println("Profile URL:\t" + mePerson.getUrl());

    try {
        PlusDomains plusDomains = new PlusDomains.Builder(new NetHttpTransport(), new JacksonFactory(), credential)
                .setApplicationName("GNEWS.ID")
                .build();

        com.google.api.services.plusDomains.model.Person me = plusDomains.people().get(mePerson.getId()).execute();
        System.out.println("ID:\t" + me.getId());
        System.out.println("Profile URL:\t" + me.getUrl());
    }catch (IOException e) {
        e.printStackTrace();
    }

    System.out.println("G+ has been connected!");
    return "redirect:/cms/connection";
}
这是日志

com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden {


"code" : 403,
  "errors" : [ {
    "domain" : "global",
    "message" : "Forbidden",
    "reason" : "forbidden"
  } ],
  "message" : "Forbidden"
}
    at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1065)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
    at io.gnews.cms.controller.GplusController.gplusCallback(GplusController.java:140)

我读过,也读过。但他们的案例出现在google Plus页面上,而我的案例出现在普通用户的页面上。你知道我哪里做错了吗?

我在自动发布到G+用户的墙上时也遇到了同样的问题

此解决方案中需要注意的几点是:

  • 删除先前授予的权限,请访问accounts.google.com
  • 范围请求-Google\u服务\u Plus::Plus\u ME\Google\u服务\u Plus域::Plus\u流\u写入
  • 我使用Guzzle请求GooglePlusDomain的RESTAPI自动发布
  • 作为参考,我创建了一个公共要点。 在gist的示例中,我使用的是php、google api php客户端、yii2。如果在解决过程中遇到任何问题,请发表评论。我会尽力帮忙的


    p.S.成功实施和测试

    我在自动发布到G+用户墙时也遇到了同样的问题

    此解决方案中需要注意的几点是:

  • 删除先前授予的权限,请访问accounts.google.com
  • 范围请求-Google\u服务\u Plus::Plus\u ME\Google\u服务\u Plus域::Plus\u流\u写入
  • 我使用Guzzle请求GooglePlusDomain的RESTAPI自动发布
  • 作为参考,我创建了一个公共要点。 在gist的示例中,我使用的是php、google api php客户端、yii2。如果在解决过程中遇到任何问题,请发表评论。我会尽力帮忙的


    p.S.成功实施并测试了

    如果谷歌账户的电子邮件地址以
    gmail.com结尾
    它将不起作用。Domains API仅适用于使用自定义域的帐户。如果我将其用于google plus页面,您认为它会起作用吗@亚伯拉罕?哦,没关系。现在我知道google在google plus页面上使用了另一个API。@Kelimutu哪一个?如果google帐户的电子邮件地址以
    gmail.com
    结尾,它将无法工作。Domains API仅适用于使用自定义域的帐户。如果我将其用于google plus页面,您认为它会起作用吗@亚伯拉罕?哦,没关系。现在我知道google在google plus页面上使用了另一个API。@Kelimutu哪一个?