naT erraT
naT erraT

Reputation: 541

Google Cloud Print "403 User credentials required"

I have seen posts with the same problem that I am facing, however, I do not get it to work, even with the changes the other posts suggests.

So when I fail with other google API's I usually get an (informative) errorcode and or message. But not in this case.

Using PHP with Guzzle i try to do this request.

$headers = [
        RequestOptions::HEADERS => [
            'Authorization' => 'Bearer ' . $oResponse->access_token,
            'X-CloudPrint-Proxy' => 'Google-JS',
            'Content-Type' => 'application/x-www-form-urlencoded',
            'Accept-Charset' => 'utf-8',
        ]
    ];

    $getPrinters = $client
        ->post('https://www.google.com/cloudprint/search?output=json', $headers)
        ->getBody()
        ->getContents();

But I get this:

Client error: `POST https://www.google.com/cloudprint/search?output=json` resulted in a `403 User credentials required` response: <HTML> <HEAD> <TITLE>User credentials required</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF" TEXT="#000000"> <H1>User credenti (truncated...)

I've tried with different kinds of headers, but they all return the same result.

$oResponse->access_token comes from this part (Which works)

    $response = $client->post('https://www.googleapis.com/oauth2/v4/token', [
        RequestOptions::FORM_PARAMS => [
            'refresh_token' => 'valid token',
            'client_id' => 'xxxxx',
            'client_secret' => 'xxxxx',
            'grant_type' => 'refresh_token'
        ],
        RequestOptions::HEADERS => [
            'Content-Type' => 'application/x-www-form-urlencoded'
        ]
    ])->getBody()->getContents();

    $oResponse = json_decode($response);

Also I didn't find anything useful on the official docs either. But again, maybe I just misinterpreted it.

I have also tried other clients for HTTP requests, like Postman and in "raw curl". But still the same result.

So. What can I do next?

Cheers

Upvotes: 0

Views: 624

Answers (1)

user1486269
user1486269

Reputation: 41

Make sure the access token is obtained via OAuth.

Also change https://www.google.com/cloudprint/search?output=json to https://www.google.com/cloudprint/search

Check : https://developers.google.com/cloud-print/docs/appInterfaces#search

/search only supports the following parameters: q, type, connection_status, use_cdd, extra_fields

Upvotes: 0

Related Questions