Adwords PHP API Array to string conversion

129 views
Skip to first unread message

simon...@outlook.com

unread,
Sep 6, 2016, 2:30:56 PM9/6/16
to AdWords API Forum
I have an error when I use $campaignService->get($selector);

$client = new \Google_Client();
/*
$client->setAuthConfigFile(base_path('google.json'));
*/
$client->setClientId(getenv('GOOGLE_ID'));
$client->setClientSecret(getenv('GOOGLE_SECRET'));
$client->addScope("https://www.googleapis.com/auth/adwords");
$client->setRedirectUri('http://localhost/lidogen/public/service/google/oauth' /*request()->url()*/ );
$client->setIncludeGrantedScopes(true);
$client->setApprovalPrompt("force");
$client->setAccessType("offline");

if (!isset($_GET['code'])) {
$auth_url = $client->createAuthUrl();
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
exit;
}
if(isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$access_token = $client->getAccessToken();

$oauth2Info = [
'client_id' => getenv('GOOGLE_ID'),
'client_secret' => getenv('GOOGLE_SECRET'),
'refresh_token' => $access_token,
];

$user = new \AdWordsUser();
$user->SetOAuth2Info($oauth2Info);

$campaignService = $user->GetService('CampaignService', 'v201603');

$selector = new \Selector();
$selector->fields = array('Id', 'Name');
$selector->ordering[] = new \OrderBy('Name', 'ASCENDING');

$selector->paging = new \Paging(0, \AdWordsConstants::RECOMMENDED_PAGE_SIZE);

$page = $campaignService->get($selector);

dd($page);
}

ErrorException in C:\xampp\htdocs\lidogen\vendor\googleads\googleads-php-lib\src\Google\Api\Ads\Common\Util\CurlUtils.php line 116:Array to string conversion

GoogleController.php

Shwetha Vastrad (AdWords API Team)

unread,
Sep 6, 2016, 3:40:17 PM9/6/16
to AdWords API Forum
Hi,

Could you try to retrieve your campaigns using the GetCampaigns example from the PHP client library? If this works successfully, you could use this example code as a reference to implement your application. If the example also encounters an error, please provide the SOAP XML request and response logs. Please use Reply privately to author when responding.

Thanks,
Shwetha, AdWords API Team.

Joven Albarida

unread,
Oct 30, 2016, 1:27:40 AM10/30/16
to AdWords API Forum
Hi,

It look like you use access_token as your refresh_token..
refresh_token' => $access_token,

Thanks
Reply all
Reply to author
Forward
0 new messages