【发布时间】:2017-05-04 13:55:24
【问题描述】:
我有access_token,现在尝试使用此示例从 Google API 获取 fata:
https://developers.google.com/android-publisher/api-ref/edits/details/get
我尝试获取对这个 URL 执行查询的数据:
https://www.googleapis.com/androidpublisher/v2/applications/packageName/edits/editId
$curl = new Curl();
$curl->get('https://www.googleapis.com/androidpublisher/v1/applications/com.shazam.android&access_token='.$_SESSION['access_token']["access_token"]);
$_SESSION['access_token']["access_token"] 是 access_token
结果我收到消息:Error: 404: HTTP/1.1 404 Not Found
如何从 API 中获取信息?
这是完整的 URL 请求,它不起作用:
https://www.googleapis.com/androidpublisher/v2/applications/com.shazam.android/edits/1?access_token=ya29.Ci-5Azg5JoBiESM5cEzM3TQrP3SXHAFirFg0f-Fj83PxtrtINWQDe2L-3f5wP7oAtQ
{
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission"
}
],
"code": 403,
"message": "Insufficient Permission"
}
}
完整代码为:
// Create the client object and set the authorization configuration
// from the client_secretes.json you downloaded from the developer console.
$client = new Google_Client();
$client->setAuthConfig(__DIR__ . '/client_secrets.json');
$client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);
// If the user has already authorized this app then get an access token
// else redirect to ask the user to authorize access to Google Analytics.
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
// Set the access token on the client.
$client->setAccessToken($_SESSION['access_token']);
$curl = new Curl();
$curl->get('https://www.googleapis.com/androidpublisher/v1/applications/com.shazam.android/edits/1/&access_token='.$_SESSION['access_token']["access_token"]);
if ($curl->error) {
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage . "\n";
} else {
echo 'Response:' . "\n";
var_dump($curl->response);
}
// Create an authorized analytics service object.
//$analytics = new Google_Service_Analytics($client);
// Get the first view (profile) id for the authorized user.
//$profile = getFirstProfileId($analytics);
// Get the results from the Core Reporting API and print the results.
//$results = getResults($analytics, $profile);
//printResults($results);
} else {
$redirect_uri = 'http://localhost/play/oauth2callback.php';
header('Location: ' . $redirect_uri);
}
在得到access_token 之后,我尝试发出Curl 请求:
$curl = new Curl();
$curl->get('https://www.googleapis.com/androidpublisher/v1/applications/com.shazam.android/edits/1/&access_token='.$_SESSION['access_token']["access_token"]);
【问题讨论】:
-
您的获取请求缺少来自请求“edits/editId”developers.google.com/android-publisher/api-ref/edits/get 的最后一个参数
-
这个参数应该包含什么内容?
-
如果您将其正确格式化为获取请求,它可能吗? != &
-
我用正确的查询更新了问题
-
Insufficient Permission 告诉您问题出在哪里,然后您进行身份验证的用户无权查看。
标签: google-api google-api-php-client google-play-games google-api-client