$profileID = *******;
$id = ********;
$accesstoken = 'Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$opts = array(
"http" => array(
"method" => "GET",
'header' => 'Authorization: Bearer '.$accesstoken.
'Accept: application/json'
)
);
$context = stream_context_create($opts);
$url = 'https://www.googleapis.com/dfareporting/v3.3/userprofiles/'.$profileID.'/campaigns/'.$id;
$response = file_get_contents($url,false,$context);
echo '<pre>';
print_r($response);
echo '</pre>';
I've read the documentation, I chosen to use the Authorization Bearer option in the header. All I get in return is 'Warning: file_get_contents(https://www.googleapis.com/dfareporting/v3.3/userprofiles/XXXXXX/campaigns/XXXXXXXX): failed to open stream: HTTP request failed! HTTP/1.0 401 Unauthorized in /my/file/path/file.php on line 93'
I'm just trying to return a campaign by id.
I have my oauth2 set up. I've returned information using the sample files and examples but I don't feel like reverse engineering many php scripts just to get impressions of some campaign. I have a tokenStore.json with my access token. I've used composer to get a vendor folder and client secrets. I've been connecting to many the "Getting Started" examples ranging from Google Analytics to Display & Video 360 but I NEVER figured out how to utilize these types of pages. Which seems way more useful than deconstructing the OOP hierarchy these Google fellas make.
My access token is valid and I don't need an API key if I chose this way to getting a HTTP request. I can run GetCampaigns.php right now and I'll get a correct answer.
When trying the cURL option with:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_HTTPHEADER, $opts);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo '<pre>';
print_r($output);
echo '</pre>';
I get a json object saying:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
Please any idea would help.