Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't download report with php #70

Open
kikusempai opened this issue May 20, 2016 · 12 comments
Open

Can't download report with php #70

kikusempai opened this issue May 20, 2016 · 12 comments

Comments

@kikusempai
Copy link

In file api-samples/php/retrieve_reports.php on lines 149-150 an error is triggered by this code:

$request = $youtubeReporting->media->download("");
$request->setUrl($reportUrl);

Method setUrl() is not defined in class GuzzleHttp\Psr7\Request.

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:

$uri = new GuzzleHttp\Psr7\Uri($reportUrl);
$request = new GuzzleHttp\Psr7\Request('get', $uri);

It removes existing error. But the new one is generated:

Fatal error: Call to undefined method GuzzleHttp\Psr7\Response::getResponseBody()

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.

@iblessedi
Copy link

One more person is waiting for the solution!

@TLMcode
Copy link

TLMcode commented Jul 14, 2016

Good luck getting any help with any of this.

@liamseys
Copy link

I have the same problem.

@GregoirePiat
Copy link

Same issue here ...

@aymanbaba
Copy link

Same issue here...come guys, help us out here please

@CTadmin
Copy link

CTadmin commented Dec 15, 2016

The bug is being backed on Bountysource
https://www.bountysource.com/issues/34440456-can-t-download-report-with-php

@caruanas
Copy link

Same here. Anyone had any luck?

@0fs
Copy link

0fs commented Mar 23, 2017

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);

@jpriceonline
Copy link

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?

@daniel-zahariev
Copy link

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: #131

@aymanbaba
Copy link

aymanbaba commented Aug 3, 2017

This has worked like a charm. Thank You @daniel-zahariev

Now @youtube, please update your sample code

AndyDiamondstein added a commit that referenced this issue Aug 16, 2017
Fix report downloading in PHP example #70
@Aswinpookkatt
Copy link

Why is the issue still open?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

13 participants