Open kikusempai opened 8 years ago
One more person is waiting for the solution!
Good luck getting any help with any of this.
I have the same problem.
Same issue here ...
Same issue here...come guys, help us out here please
The bug is being backed on Bountysource https://www.bountysource.com/issues/34440456-can-t-download-report-with-php
Same here. Anyone had any luck?
It works for me:
$googleClient->setDefer(true);
$autorization = json_decode($googleClient->getAccessToken())->token_type.' '.json_decode($googleClient->getAccessToken())->access_token;
$headers = [
'authorization' => $autorization,
'alt' => 'media'
];
$request = new Google_Http_Request(
$report->downloadUrl,
'GET',
$headers
);
$request->enableExpectedRaw();
$response = $googleClient->execute($request);
$googleClient->setDefer(false);
instead of
$client->setDefer(true);
// Call the YouTube Reporting API's media.download method to download a report.
$request = $youtubeReporting->media->download("");
$request->setUrl($reportUrl);
$response = $client->execute($request);
file_put_contents("reportFile", $response->getResponseBody());
$client->setDefer(false);
Google_Http_Request was removed a while back right? All the way back in July 2016: https://github.com/google/google-api-php-client/blob/master/UPGRADING.md.
Just interested to know if that still works? @sflechie your solution looks the most promising, just not sure on the Google_Http_Request?
Faced the same issue and here's how i fixed it:
function downloadReport(Google_Service_YouTubeReporting $youtubeReporting, $reportUrl, &$htmlBody) {
$client = $youtubeReporting->getClient();
$client->setDefer(true);
// Setting 'alt' param here fixes the first half of the issue
$request = $youtubeReporting->media->download("", array("alt" => "media"));
// Correctly updating the URL fixes the second half
$request = $request->withUri(new \GuzzleHttp\Psr7\Uri($reportUrl));
$response = $client->execute($request);
file_put_contents("reportFile", $response->getBody());
$client->setDefer(false);
}
And here's my pull request: https://github.com/youtube/api-samples/pull/131
This has worked like a charm. Thank You @daniel-zahariev
Now @YouTube, please update your sample code
Why is the issue still open?
In file api-samples/php/retrieve_reports.php on lines 149-150 an error is triggered by this code:
What's more important, that Request object doesn't have such field. It has URI (GuzzleHttp\Psr7\Uri Object). So I replaced that lines with following:
It removes existing error. But the new one is generated:
Even changing $request->getResponseBody() to $response->getStream()->getContents() doesn't really help or download a proper report.
Can anyone help me on this?
Thank you in advance.