【发布时间】:2020-02-27 15:46:33
【问题描述】:
我正在尝试使用 Google Admob API Java 客户端,描述为 here,但我收到了以下回复:
{
"code" : 0,
"error" : {
"code" : 403,
"message" : "Request had insufficient authentication scopes.",
"errors" : [ {
"message" : "Insufficient Permission",
"domain" : "global",
"reason" : "insufficientPermissions"
} ],
"status" : "PERMISSION_DENIED"
}
}
这就是我获取凭据的方式:
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
new InputStreamReader(GoogleConnector.class.getResourceAsStream("/client_secrets_tt.json")));
// set up authorization code flow
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
httpTransport, JSON_FACTORY, clientSecrets,
Collections.singleton("https://www.googleapis.com/auth/admob.report")).setDataStoreFactory(
dataStoreFactory).build();
// authorize
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize(userId);
这是我的 Admob 客户端:
AdMob adMobClient = new AdMob.Builder(
httpTransport,
jsonFactory,
request -> {
credential.initialize(request);
request.setParser(new JsonObjectParser(jsonFactory));
})
.setRootUrl("https://admob.googleapis.com")
.setApplicationName(applicationName)
.build();
return adMobClient;
我还在 OAuth 同意屏幕中手动添加了范围 https://www.googleapis.com/auth/admob.report。
有人可以帮助我或建议这可能是什么原因吗?
【问题讨论】:
标签: java google-api admob