Search code examples
phpgoogle-apigoogle-drive-apigoogle-slides-apigoogle-php-sdk

Download google slide via google api with raw request


I am new to google developer's api, my goal is to download google slide from google drive to my server with raw request in php only not with the pdk sdk. I have done the following step:

1) I got access_token by authenticate process by giving all the mandatory scope.

2) Now i go to https://www.googleapis.com/drive/v2/files/FILEID to get file metadata in response i get the exportLinks array() in that i get the download slide url by which i can get the slide from google drive to my server. Suppose below is the final exportLinks which i want

https://docs.google.com/feeds/download/presentations/Export?id=MYFILEID&exportFormat=pptx

If i hit above URL in the browser the valid file is downloading Now the actual problem comes i code to download file from above url to my server like below:

<?php 

$c = file_get_contents("https://docs.google.com/feeds/download/presentations/Export?id=MYFILEID&exportFormat=pptx");

file_put_contents('new.pptx', $c);

Now the file new.pptx is creating on my server which is invalid means the size is incorrect about 75kb actuall size is about 11mb and also it is not opening in the powerpoint showing error like unreadable content found

Please help me how can i download valid google slide from google drive to my server..

I did Research and came to the point that if you have to download the google slide from google drive to your server so point to the exportLinks am i right here ?

May be my way is not correct, so please correct me.


Solution

  • I got the issue where i was wrong, i was accessing the exportLinks directly but it should have accessed by the access token in the header with Curl thanks @ Tanaike