在PHP中发布来自谷歌应用引擎SDK的inapp产品



我想把inapp产品发布到Google Play商店。为此,我使用下面的链接

https://developers.google.com/android-publisher/api-ref/inappproducts/insert

这是我下面的代码:

include_once "templates/base.php";
session_start();
require_once 'Google/Client.php';
require_once 'Google/Google_AndroidPublisherService.php';
require_once 'Google/Service/AndroidPublisher.php';
require_once 'Google/Google_AssertionCredentials.php';
$client_id = 'xxxxxxxxxxxxxxx';
$client_secret = 'xxxxxxxxxxxxxx';
$redirect_uri = 'http://localhost:8080';

$client = new Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->addScope("https://www.googleapis.com/auth/androidpublisher");

$AndroidPublisherService = new Google_Service_AndroidPublisher($client);
if (isset($_GET['code'])) {
    $client->authenticate($_GET['code']);
    $_SESSION['access_token'] = $client->getAccessToken();
    $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
    header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
$data = '{
  "packageName": "com.rhyme",
  "sku": "com.book2",
  "status": "true",
  "purchaseType": "subscription",
  "defaultPrice": {
    "priceMicros": "5000",
    "currency": "INR"
  },
  "prices": {
    (key): {
      "priceMicros": "",
      "currency": ""
    }
  },
  "listings": {
    (key): {
      "title": "testing",
      "description": "testing"
    }
  },
  "defaultLanguage": "en-us",
  "subscriptionPeriod": "",
  "season": {
    "start": {
      "month": "09",
      "day": "11"
    },
    "end": {
      "month": "12",
      "day": "23"
    }
  },
  "trialPeriod": ""
}';

$post = file_get_contents('https://www.googleapis.com/androidpublisher/v2/applications/com.rhyme/inappproducts',null,stream_context_create(array(
    'http' => array(
        'method'           => 'POST',
        'content'          => $data,
    ),
)));
echo "<pre>";
print_r($post);
if ($post) {
    echo $post;
} else {
    echo "POST failed";
}

我正在获取访问令牌。但当我执行链接https://www.googleapis.com/androidpublisher/v2/applications/com.rhyme/inappproducts时,它会给出一个json错误,如下所示:-

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"

我不知道哪里出了问题。请给我一些建议。

由于您已经在使用API客户端库,因此您应该执行类似以下的操作

$AndroidPublisherService->inappproducts->insert('com.rhyme', $data);

而不是直接使用CCD_ 2。

相关内容

  • 没有找到相关文章

最新更新