我想使用 PHP 和 Google Play Developer API 来保护和验证应用内购买以防止伪造交易。我已经为此审查了 Google Docs。我首先通过完成此链接https://developers.google.com/android-publisher/authorization中的步骤创建了一个 access_token 。然后我尝试执行此链接https://developers.google.com/android-publisher/api-ref/purchases/products/get#auth中描述的操作,但我失败了。我的代码和我得到的结果如下。
我的代码:
<?php
$curl = curl_init();
$headers = array(
'access_token: my_access_token',
'expires_in: 3600',
'token_type: Bearer'
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_URL, "https://www.googleapis.com/androidpublisher/v2/applications/my.package.name/purchases/products/myProductId/tokens/myPurchaseToken");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result=curl_exec($curl);
echo $result;
curl_close($curl);
?>
结果:
{
error: {
errors: [
{
domain: "global",
reason: "required",
message: "Login Required",
locationType: "header",
location: "Authorization"
}
],
code: 401,
message: "Login Required"
}
}
我哪里做错了,我该怎么办?从现在开始谢谢你。