首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“服务帐户”androidpublisher验证订阅购买-> 401“此开发人员帐户不拥有应用程序”

“服务帐户”androidpublisher验证订阅购买-> 401“此开发人员帐户不拥有应用程序”
EN

Stack Overflow用户
提问于 2013-10-10 01:42:04
回答 1查看 2.5K关注 0票数 1

接口版本: google- api -php-client-0.6.7

我需要通过我的php脚本在我的服务器上验证用户从我的android应用程序购买的android订阅。

因此,没有用户交互,用户将只发送他的购买令牌到我的服务器,我的服务器将验证是否是有效的购买。

我发现不需要用户交互的唯一方法似乎是“服务帐户”,所以我遵循documentation并创建了CLIENT_ID、SERVICE_ACCOUNT_NAME、KEY_FILE也用于测试,我使用了来自我的应用程序$ANDROIDUsertoken的真实购买令牌

这是我的服务器脚本(出于安全原因,我更改了一些代码部分):

代码语言:javascript
复制
<?php
include_once('../lib/google-api-php-client/src/Google_Client.php');
include_once('../lib/google-api-php-client/src/contrib/Google_AndroidpublisherService.php');

//user token, in json format
$ANDROIDUsertoken = '{"orderId":"....","packageName":"....","productId":"....","purchaseTime":....,"purchaseState":0,"purchaseToken":"...."}';
$user_token= json_decode($ANDROIDUsertoken,true);

// https://developers.google.com/console/help/#service_accounts
const CLIENT_ID = 'something-private.apps.googleusercontent.com';
const SERVICE_ACCOUNT_NAME = 'something-private@developer.gserviceaccount.com';
const KEY_FILE = 'secret-dir/privatekey.p12';

$client = new Google_Client();
$client->setApplicationName($user_token['packageName']);
$client->setClientId(CLIENT_ID);
$key = file_get_contents(KEY_FILE);

echo "start auth:<br>";

$auth = new Google_AssertionCredentials(
    SERVICE_ACCOUNT_NAME,
    array('https://www.googleapis.com/auth/androidpublisher'),
    $key);

$client->setAssertionCredentials($auth);

//$client->getAuth()->refreshTokenWithAssertion();
//$accessToken=$client->getAccessToken();
//$client->setAccessToken($accessToken);

echo "start requests:<br>";

$AndroidPublisherService = new Google_AndroidPublisherService($client);
$res = $AndroidPublisherService->purchases->get($user_token['packageName'], $user_token['productId'], $user_token['purchaseToken']);

var_dump($res);
?>

错误:

代码语言:javascript
复制
start auth:
start requests:
Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling GET https://www.googleapis.com/androidpublisher/v1.1/applications/..APPLICATION../subscriptions/..PRODUCT../purchases/..TOKEN..: 
(401) This developer account does not own the application.' in /..PATH TO MY WEBSERVER../lib/google-api-php-client/src/io/Google_REST.php on line 66

我以前也在"web应用程序“上成功地使用了OAuth+androidpublisher,但需要用户交互,这不是我的目标(我需要一个服务器端检查)

请注意,$AndroidPublisherService->purchases>get代表订阅

我看到了this的帖子,但有点不同,对我不起作用

EN

回答 1

Stack Overflow用户

发布于 2014-07-08 17:57:17

好了,我找到解决方案了!

你必须将你的API和你的应用连接起来。您必须转到您的谷歌Play发布页面(https://play.google.com/apps/publish),并在设置->用户帐户和权限->邀请新用户中使用服务帐户电子邮件邀请用户,并为其提供“查看财务报告”的权限。

谢谢对我很有用,祝你好运!

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19279031

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档