douwen8424 2018-09-05 11:16
浏览 66
已采纳

Google AnalyticsAPI v3> analytics.management.uploads.uploadData权限不足问题

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();
}

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

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.

  • 写回答

1条回答 默认 最新

  • dtufl26404 2018-09-05 11:33
    关注

    (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

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

    Then the following request will run.

    /**
     * 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();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?