Cargue el archivo en Google Drive usando el token de acceso. ¿Qué alcance de autenticación se requiere?

I am trying to upload a file to Google Drive with PHP.

For the authorization code, I am using the following scopes:  

I already received a valid refresh_token, and I'm able to use it to fetch a new access_token anytime I wish.

Now the problem is when I am trying to perform the upload using this access_token (it is not exprired, and not used yet) dice:

stdClass Object
    [error] => stdClass Object
            [errors] => Array
                    [0] => stdClass Object
                            [domain] => global
                            [reason] => required
                            [message] => Login Required
                            [locationType] => header
                            [location] => Authorization


            [code] => 401
            [message] => Login Required

I am using curl with following header:

    [0] => Content-Type: text/plain
    [1] => Content-Length: 503242
    [2] => Authorization: Bearer ya29.AHES6ZRWXZkZDDi6AFV9PK2QonHp93nIfJbYqipXFT1uCsg
    [3] => GData-Version: 3.0

And following URL:

The CURL Command is like:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADERS, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($file));
$return = curl_exec($ch);

Any Help will be heartly appreciated... Thanks in advance...

preguntado el 28 de agosto de 12 a las 14:08

3 Respuestas

The only OAuth scope you need to upload a file to Drive is

For all possible scopes, check the documentation:

By the way, the Drive API is not GData-based so you don't need to add the GData-Version encabezado a sus solicitudes.

I'd also recommend you to compare your requests with those sent by the OAuth 2.0 Playground so that it should be easy to spot the error:

Respondido 28 ago 12, 18:08

Try using the following scope:

Also verify that you have gone through the steps given in documentation thoroughly

If you don't want to use curl.You can use insert method of Googlephpclientlibarary of inserting files.

Otherwise compare request with OauthPlayground as mentioned by Claudio

Respondido 30 ago 12, 12:08

I was in very much hurry, and after much effort the whole night, I came to a point where I made a minor modification in the Google API Client Library... And guess what! It works!! I am off desk right now, Will post the changes later... Thanks, Claudio y Trim Kaur - Izhar Aazmi


Respondido 17 Oct 15, 19:10

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.