我想复制Google Doc电子表格文件。我正在使用<{3}}
function copyFile($service, $originFileId, $copyTitle) {
$copiedFile = new Google_DriveFile();
$copiedFile->setTitle($copyTitle);
try {
return $service->files->copy($originFileId, $copiedFile);
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}
return NULL;
}
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
$client = new Google_Client();
// Get your credentials from the console
$client->setClientId('myclientid');
$client->setClientSecret('myclient secret');
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
$client->setScopes(array('https://www.googleapis.com/auth/drive'));
$service = new Google_DriveService($client);
copyFile($service,'my schema id','Copy Of Schema');
我无法获得$ service实例。所以我搜索并获得了上述方法,但现在它提供了401登录所需的错误。
请帮帮我
答案 0 :(得分:0)
您需要检查用户是否有足够的授权
$ authUrl = $ client-&gt; createAuthUrl();
将用户重定向到authUrl
让用户粘贴授权码:
$authCode = trim(fgets(STDIN));
$ accessToken = $ client-&gt; authenticate($ authCode);
$客户端 - &GT; setAccessToken($的accessToken);
参考:Click here