访问Google我的商家API进行评论返回“找不到404方法”

时间:2019-01-03 07:22:12

标签: java review google-my-business-api

我想从GMB API获得评论,并且在调用时得到 404方法未找到

我已经在Google上注册了我的公司,并且也对此发表了一些评论。我还设置了刷新令牌和使用Java代码中的OAuth client_id和client_secret获取的访问令牌。

以下是我在运行服务时遇到的错误。

WARNING: unable to change permissions for owner: 
C:\Users\anubhavs1\.store\mybusiness_sample
Exception in thread "main" 
com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not 
Found
{
  "code" : 404,
  "errors" : [ {
    "domain" : "global",
    "message" : "Method not found.",
    "reason" : "notFound"
  } ],
  "message" : "Method not found.",
  "status" : "NOT_FOUND"
} at 
com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:150)
    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:1067)
    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 com.kpit.bs.Main.listAccounts(Main.java:112) at    com.kpit.bs.Main.main(Main.java:97)

我已完成以下操作

**Main Method**
public static void main(String[] args) throws Exception {
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
Credential credential = authorize();

credential.setAccessToken("##Access Token from Authorization Server##");
credential.setRefreshToken("##Refresh Token from Authorization Server##");

mybusiness = new MyBusiness.Builder(httpTransport, JSON_FACTORY, 
credential).setApplicationName(APPLICATION_NAME).build();

MyBusiness.Accounts.List accountsList = mybusiness.accounts().list();
ListAccountsResponse response = accountsList.execute();      
java.util.List<Account> accounts = response.getAccounts();                       
for (Account account : accounts) {
System.out.println(account.toPrettyString());
    }
  }

**Authorize Method**
private static Credential authorize() throws Exception {
InputStream secrets = 
Main.class.getResourceAsStream("/client_secrets.json");
if (secrets == null) {
        System.out.println(
                "Enter Client ID and Secret from Google 
API  Console " + "into google-my-business-api- 
sample/src/main/resources/client_secrets.json");
        System.exit(1);
    }
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, 
new InputStreamReader(secrets));
    if 
(clientSecrets.getDetails().getClientId().startsWith("Enter") || 
clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
        System.out.println(
                "Enter Client ID and Secret from Google 
API Console " + "into google-my-business-api- 
sample/src/main/resources/client_secrets.json");
        System.exit(1);
    }
GoogleAuthorizationCodeFlow flow = new 
GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, 
clientSecrets, Collections.singleton 
("https://www.googleapis.com/auth/plus.business.manage")).    
setDataStoreFactory(dataStoreFactory).setAccessType("offline")
                    .build();
return new AuthorizationCodeInstalledApp(flow, new 
LocalServerReceiver.Builder().setPort(8080).build()).authorize("user");
}

我的目的是检索发布在帐户上但当前无法获得帐户详细信息的评论。

0 个答案:

没有答案