【问题标题】:"Service Accounts" androidpublisher verify subscription purchase -> 401 "This developer account does not own the application"“服务帐户” androidpublisher 验证订阅购买 - > 401 “此开发者帐户不拥有该应用程序”
【发布时间】:2013-10-09 17:42:03
【问题描述】:

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

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

因此,没有用户交互,用户只会将其购买的令牌发送到我的服务器,我的服务器将验证是否是有效购买。
我发现不需要用户交互的唯一方法似乎是“服务帐户”,所以我遵循documentation 并制作了 CLIENT_ID,SERVICE_ACCOUNT_NAME,KEY_FILE ,为了进行测试,我使用了我的应用程序中的真实购买令牌$ANDROIDUsertoken

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

<?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);
?>

错误:

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

我之前也成功使用 OAuth+androidpublisher 在“Web 应用程序”上工作,但这需要用户交互,这不是我的目标(我需要服务器端检查)

注意 $AndroidPublisherService->purchases->get stand for subscription

我看到了this 的帖子,但略有不同,不适合我

【问题讨论】:

    标签: in-app-purchase in-app-billing google-api-php-client


    【解决方案1】:

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

    您必须将您的 API 与您的应用程序连接起来。您必须进入您的 Google Play 发布页面 (https://play.google.com/apps/publish) 并在设置->用户帐户和权限->邀请新用户并授予其“查看财务报告”权限中使用服务帐户电子邮件邀请用户。

    感谢为我工作,祝你好运!

    【讨论】:

    • 好的,保持冷静,呼吸。一旦你将你的 API 与你的 android 应用程序连接起来,就不需要任何其他“用户交互”,你将能够在没有用户交互的情况下执行你的脚本,相信我。
    • 对不起,如果我不友好,“没有用户交互”意味着我的应用程序的所有用户除了下载和安装应用程序外不需要做任何事情
    猜你喜欢
    • 2012-06-13
    • 1970-01-01
    • 2012-03-25
    • 2023-02-19
    • 1970-01-01
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多