Google Analytics API v3> analytics.management.uploads.uploadData权限不足问题 [英] Google Analytics API v3 > analytics.management.uploads.uploadData Insufficient Permission Problem

查看:98
本文介绍了Google Analytics API v3> analytics.management.uploads.uploadData权限不足问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个PHP应用程序,它将退款数据发送到分析工具.我想通过数据上传发送退款.我使用了 Google API PHP客户端库,因此以下代码使用了可以在这里找到:

I have developed a PHP application which will send refund data to analytics. I want to send the refund via data upload. I use the Google APIs PHP client library so the following code uses the method you can find here: https://github.com/google/google-api-php-client-services/blob/a016ea7b6d47e1fd1f43d89ebd80059d4bfadb32/src/Google/Service/Analytics/Resource/ManagementUploads.php

$dataTxt = "ga:transactionId;ga:quantityRefunded;ga:productSku;ga:productPrice
dcn15355709483497;1;2811841;38.47
dcn15360003605123;1;3568636;89.35
dcn15359475814131;1;4238610;28.98";

$accountId = "xxxx"; # admin -> choose account -> view properties
$webPropertyId = "xxxx"; # admin -> choose property -> view properties
$customDataSourceId = "xxxx";    
$data = array(
    'data' => $dataTxt,
    'mimeType' => 'application/octet-stream',
    'uploadType' => 'media');
try {
    $this->service->management_uploads->uploadData(
        $accountId,
        $webPropertyId,
        $customDataSourceId,
        $data
    );

} catch (apiServiceException $e) {
    print 'There was an Analytics API service error '
        . $e->getCode() . ':' . $e->getMessage();

} catch (apiException $e) {
    print 'There was a general API error '
        . $e->getCode() . ':' . $e->getMessage();
}

我向API用户授予了完全访问权限,并授予了他任何东西.我仍然收到错误:

I gave the API user full access and granted him anything. i still get the error:

调用POST时出错 https://www.googleapis.com/upload/analytics/v3/management/accounts/2465955/webproperties/UA-2465955-20/customDataSources/gx3hqqEjR7qBrcgrIDkToQ/uploads?uploadType=media :( 403)权限不足

Error calling POST https://www.googleapis.com/upload/analytics/v3/management/accounts/2465955/webproperties/UA-2465955-20/customDataSources/gx3hqqEjR7qBrcgrIDkToQ/uploads?uploadType=media: (403) Insufficient Permission

我希望有人能帮助我,因为我没有答案和问题.

I hope someone can help me, because i run out of answeres and questions.

推荐答案

(403)权限不足

(403) Insufficient Permission

意味着您通过身份验证的用户没有授予您足够的权限来执行您尝试做的事情.不幸的是,您尚未包含身份验证代码.但我可以告诉您上传数据

Means that the user you are authenticated with has not granted you enough permissions to do what you are trying to do. Unfortunately you have not included your authentication code. But i can tell you that upload data

要求用户通过以下范围之一进行身份验证

Requires that the user be authenticated with one of the following scopes

  • https://www.googleapis.com/auth/analytics
  • https://www.googleapis.com/auth/analytics.edit

您应该遵循以下示例进行自动化 PHP快速入门,请确保您使用的是适当的范围.

You should be following this example for authecation PHP quick start make sure that you are using the proper scope.

然后将运行以下请求.

/**
 * Note: This code assumes you have an authorized Analytics service object.
 * See the Data Import Developer Guide for details.
 */

/**
 * This request uploads a file to a custom data source.
 */
try {
  $analytics->management_uploads->uploadData(
      '123456',
      'UA-123456-1',
      '122333444455555',
      array('data' => file_get_contents('example.csv'),
            'mimeType' => 'application/octet-stream',
            'uploadType' => 'media'));

} catch (apiServiceException $e) {
  print 'There was an Analytics API service error '
      . $e->getCode() . ':' . $e->getMessage();

} catch (apiException $e) {
  print 'There was a general API error '
      . $e->getCode() . ':' . $e->getMessage();
}

这篇关于Google Analytics API v3> analytics.management.uploads.uploadData权限不足问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆