簡體   English   中英

如何代表您的客戶使用Google Ads API訪問

[英]How to use google ads api access on behalf your client

我是googleads庫的新手,並且遇到了問題

我將google adswords api庫添加到了新的laravel 5.3中。

我使用ini文件撥打電話並檢索數據,但是當我嘗試在此庫的Wiki中代表您的客戶使用訪問權限時

但是它不起作用我不明白的最后一部分

  4.  You can now use the OAuth2 object to make calls using the client library.

use Google\AdsApi\AdWords\AdWordsServices;
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
use Google\AdsApi\Common\OAuth2TokenBuilder;

$session = (new AdWordsSessionBuilder())
    ->fromFile()
    ->withOAuth2Credential($oauth2)
    ->build();

$adWordsServices = new AdWordsServices();

$campaignService =
    $adWordsServices->get($session, 'CampaignService', 'v201603', 'cm');

// Make calls using $campaignService.

當我嘗試示例中的代碼時,他們給了我錯誤Undefined variable: oauth2

我嘗試將其從會話中的連接文件中放入並在示例文件中檢索到它,但是沒有用

還有一個問題 :

我在哪里代表您的客戶放置ClientCustomerId?

謝謝

首先,您缺少一小步。 您需要按照本教程中的指示操作OAuth2實例,

session_start();

$oauth2 = new OAuth2([
    'authorizationUri' => 'https://accounts.google.com/o/oauth2/v2/auth',
    'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token',
    'redirectUri' => '****',
    'clientId' => '****',
    'clientSecret' => '****',
    'scope' => '****'
]);

應將ClientCustomerId放在adsapi_php.ini文件中,您可以在Github上找到該文件。

一段時間后,我發現我的問題的答案:

首先:

當我嘗試示例中的代碼時,他們給了我錯誤未定義的變量:oauth2

我嘗試將其從會話中的連接文件中放入並在示例文件中檢索到它,但是沒有用

這個問題的答案是在Wiki中,他們將代碼存儲在一個文件中。 因此,如果您想將代碼工作放在一個文件中。 如果要將其放在其他文件中,或者將一個oauth2用於多個文件,則只需傳遞它

通過路線請求

或通過中間件

(laravel 5. * $request->attributes->add(['the_name_you_want' => $client]);您可以通過以下代碼檢索它: $client = \\Request::get('the_name_you_want')

對於第二個問題:

我在哪里代表您的客戶放置ClientCustomerId?

像這樣將其放在選擇器部分中很容易找到

$session = (new AdWordsSessionBuilder())
    ->fromFile()
    ->withClientCustomerId('xxx-xxx-xxxx') //change it to what you want
    ->withOAuth2Credential($client)
    ->build();

這是我的問題的最后

感謝您對誰的幫助;)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM