PHP : Upload File To Google Drive

  1. Download Google Drive SDK.
  2. PHP Code :<!–?phprequire_once ‘src/Google/autoload.php’;$client = new Google_Client();
    // Get your credentials from the console
    $client->setClientId(‘CLIENT ID’);
    $client->setClientSecret(‘CLIENT SECRET’);
    //$client->setRedirectUri(‘REDIRECT URL’);
    $client->setScopes(array(‘https://www.googleapis.com/auth/drive&#8217;));
    $client->setAccessType(‘offline’);
    $service = new Google_Service_Drive($client);
    $authUrl = $client->createAuthUrl();
    try{
    //Request authorization
    print “Please visit:<br/>$authUrl<br/>\n”;
    print “Please enter the auth code:\n”;

    $client->setApprovalPrompt(‘force’);
    $authCode = trim(“AUTH CODE”);
    // Exchange authorization code for access token
    $accessToken = $client->authenticate($authCode);
    print_r($accessToken);

}catch(Exception  $e){
echo $e->getMessage();
}

?>

Continue reading