首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用PHP在Google App Engine SDK中发布应用内产品

使用PHP在Google App Engine SDK中发布应用内产品
EN

Stack Overflow用户
提问于 2014-09-18 04:10:52
回答 1查看 683关注 0票数 1

我想将应用程序中的产品发布到Google Play商店。为此,我使用下面的链接

代码语言:javascript
复制
https://developers.google.com/android-publisher/api-ref/inappproducts/insert

下面是我的代码:

代码语言:javascript
复制
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错误:-

代码语言:javascript
复制
{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"

我不知道我错在哪里。请为我提供相关建议。

EN

回答 1

Stack Overflow用户

发布于 2014-09-24 17:47:06

由于您已经在使用API客户端库,因此您应该这样做

代码语言:javascript
复制
$AndroidPublisherService->inappproducts->insert('com.rhyme', $data);

而不是直接使用file_get_contents

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

https://stackoverflow.com/questions/25899508

复制
相关文章

相似问题

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