showcio / google-api-php-client

Automatically exported from code.google.com/p/google-api-php-client
0 stars 0 forks source link

Error 401 - This developer account does not own the application #350

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Using new function 
$service->inapppurchases->get({APP_PACKAGE_NAME},{PRODUCT_ID}, 
{PURCHASE_TOKEN});

What is the expected output? What do you see instead?
Google_InappPurchase object with consumptionState, developerPayload, kind, 
purchaseState and purchaseTime.

What version of the product are you using? On what operating system?
google-api-php-client 0.6.3

Please provide any additional information below.
I use same account in Google API Console(https://code.google.com/apis/console) 
and Google Developer Console (https://play.google.com/apps/publish/).

My code is:
require_once '../../src/Google_Client.php';
require_once '../../src/contrib/Google_AndroidpublisherService.php';

const CLIENT_ID = 'asdf.apps.googleusercontent.com';
const SERVICE_ACCOUNT_NAME = 'asdf@developer.gserviceaccount.com';
const KEY_FILE = '../../asdf/privatekey.p12';;

$client = new Google_Client();
$client->setApplicationName({APP_PACKAGE_NAME});

session_start();
if (isset($_SESSION['token'])) {
 $client->setAccessToken($_SESSION['token']);
}

$key = file_get_contents(KEY_FILE);
$client->setAssertionCredentials(new Google_AssertionCredentials(
    SERVICE_ACCOUNT_NAME,
    array('https://www.googleapis.com/auth/androidpublisher'),
    $key)
);

$client->setClientId(CLIENT_ID);
$service = new Google_AndroidPublisherService($client);
$res = 
$service->inapppurchases->get({APP_PACKAGE_NAME},{APP_PACKAGE_NAME.PRODUCT_ID}, 
{PURCHASE_TOKEN});
var_dump($res);

Original issue reported on code.google.com by sergi...@gmail.com on 21 Jul 2013 at 7:14

GoogleCodeExporter commented 8 years ago
Looks like that API does not support service accounts: 
https://code.google.com/p/google-api-ruby-client/issues/detail?id=72

Original comment by ianbar...@google.com on 24 Jul 2013 at 2:24

GoogleCodeExporter commented 8 years ago
I think my problem was because I was trying to use Service Accounts with a 
Google Apps Gmail own account ( non @gmail.com account ).
I had to delegate domain-wide authority to my service account.
And I had to instantiate a Android Publisher Service as follows: ( only founded 
in Google Api Drive documentation ).
I added "sub" parameter programmatically in Google_AssertionCredentials like 
follows:
$auth = new Google_AssertionCredentials(
    SERVICE_ACCOUNT_NAME,
    'https://www.googleapis.com/auth/androidpublisher',
    $key);
$auth->sub = "myown@email.com";
$client->setAssertionCredentials($auth);

The documentation in Google Play Android Developer API is very poor, and Google 
Support doesn't help, they redirects you to documentation. Google PHP 
developers even don't know how Service Accounts works.
In spite of having found the answer by myself, Google needs to improve all new 
Google Play In-app Billing API version 3.

Original comment by sergi...@gmail.com on 2 Aug 2013 at 12:38