Пример #1
0
    //Build the Drive Service object authorized with your Service Account
    $auth = new Google_AssertionCredentials($SERVICE_ACCOUNT_EMAIL, array($DRIVE_SCOPE), file_get_contents($SERVICE_ACCOUNT_PKCS12_FILE_PATH));
    $client = new Google_Client();
    $client->setUseObjects(true);
    $client->setAssertionCredentials($auth);
    $service = new Google_DriveService($client);
    //Create the file
    $file = new Google_DriveFile();
    $file->setTitle($vidName);
    //$file->setDescription("Please feel free to write to this document and collaborate");
    // set the default description of the document
    $file->setMimeType('application/vnd.google-apps.document');
    $file = $service->files->insert($file);
    //Give everyone permission to read and write the file
    $permission = new Google_Permission();
    $permission->setRole('writer');
    $permission->setType('anyone');
    $permission->setValue('me');
    $permission->setwithLink(true);
    $service->permissions->insert($file->getId(), $permission);
    $headURL = $file->getalternateLink();
    mysql_query("UPDATE videonodes set gdurl='{$headURL}' WHERE id='{$vid}'") or die(mysql_error());
    //echo $file->getalternateLink();
    //print_r( $file);
}
// end of gdurl
echo "<br> <font color =\"red\" size = \"5\" > If the page is not redirected automatically then please click <a href=\"" . $headURL . "\">here</a> to open the document </font>";
$hstr = "Location: " . $headURL;
header($hstr);
/* Make sure that code below does not get executed when we redirect. */
//exit;