3

I am implementing the Google Picker in a PHP site. I am able to get the file id from the Google Picker API and also I can download the file using JavaScript. Following is my callback function called in setCallback(pickerCallback) function.

function pickerCallback(data) {
    if (data.action == google.picker.Action.PICKED) {
      var fileId = data.docs[0].id;
      document.getElementById('googleFileId').value = fileId;
      var name = data.docs[0].name;
      var url = data.docs[0].url;
      var accessToken = gapi.auth.getToken().access_token;
      var request = new XMLHttpRequest();
      request.open('GET', 'https://www.googleapis.com/drive/v2/files/' + fileId);
      request.setRequestHeader('Authorization', 'Bearer ' + accessToken);
      request.addEventListener('load', function() {
          var item = JSON.parse(request.responseText);
          window.open(item.webContentLink,"_self"); //Download file in Client Side 
      });
      request.send();
    }
    var message = 'File ID of choosen file : ' + fileId;
    document.getElementById('result').innerHTML = message;
}

I can pass the file id to PHP, but to download the file I have to authenticate again. Can any one help in how to proceed with file download in PHP ?

There is a Manage Downloads help in Google Developers page but it is not working for me https://developers.google.com/drive/web/manage-downloads.

Found a question similar to this one but no answers to how to download the file in backend Download file right after picked file from google picker.

4

1 に答える 1