2017-01-11 41 views
0

在googleads庫即時通訊新和IM谷歌廣告API接入面臨的一個問題如何使用代表您的客戶

我加入谷歌adswords API庫到一個新的laravel 5.3。

我撥打電話和使用INI文件中檢索數據,但是當我嘗試使用代表您的客戶端的訪問中 this wiki of the library

,但它不工作的最後一部分我不明白

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在代表您的客戶?

謝謝

回答

0

過了一會兒,我發現回答我的問題:

第一:

當我嘗試在他們給出的示例代碼它給我的錯誤未定義的變量:的oauth2

我嘗試將它從會話中的連接文件中取出,並在 示例文件中找回它但不起作用

這個問題的答案是在wiki中,他們使代碼在一個文件中。所以如果你想把代碼放在一個文件中。如果你希望把它放在其他文件,或者使用一個的oauth2您需要幾個文件只是爲了打發它

通過路由請求

或通過中間件

(laravel 5. * $request->attributes->add(['the_name_you_want' => $client]); 和你

這裏我把ClientCustome:可以通過這個代碼$client = \Request::get('the_name_you_want')

關於第二個問題檢索代表你的客戶?

這是很容易找到剛剛把它的選擇部分這樣

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

,這是最後的我的問題

感謝幫助了誰的嘗試;)

0

首先,你錯過了一小步。你需要到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

+0

感謝你的努力,但我提到的問題中的維基,我知道它的工作,我得到了刷新令牌=>我沒有忘記它的第一部分。我的問題是如何在其他頁面使用它?我是否需要在每個頁面中編寫代碼? @cevizmx –

相關問題