Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP谷歌驱动API安装和文件上传_Php_Api_Codeigniter_Google Drive Api - Fatal编程技术网

PHP谷歌驱动API安装和文件上传

PHP谷歌驱动API安装和文件上传,php,api,codeigniter,google-drive-api,Php,Api,Codeigniter,Google Drive Api,嗨,伙计们,我正在上传文件TroughtGdriveAPI 无法找到返回错误的原因: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Gdrive{ function initialize(){ $credentials = $this->GetOAuth2Credentials($_GET['code']); $_SESSION['credentials'] =

嗨,伙计们,我正在上传文件TroughtGdriveAPI

无法找到返回错误的原因:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Gdrive{

function initialize(){
$credentials = $this->GetOAuth2Credentials($_GET['code']);
$_SESSION['credentials'] = $credentials;

}
/**
 * Exchange an authorization code for OAuth 2.0 credentials.
 *
 * @param String $authorizationCode Authorization code to exchange for an
 *     access token and refresh token.  The refresh token is only returned by
 *     Google on the very first exchange- when a user explicitly approves
 *     the authorization request.
 * @return OauthCredentials OAuth 2.0 credentials object
 */
function GetOAuth2Credentials($authorizationCode) {
  $client = new apiClient();
  $client->setClientId(Config::5112+++++.apps.****5971157@developer.gserviceaccount.com);
  $client->setRedirectUri(Config::site_url());

  /**
   * Ordinarily we wouldn't set the $_GET variable.  However, the API library's
   * authenticate() function looks for authorization code in the query string,
   * so we want to make sure it is set to the correct value passed into the
   * function arguments.
   */
  $_GET['code'] = $authorizationCode;

  $jsonCredentials = json_decode($client->authenticate());

  $oauthCredentials = new OauthCredentials(
      $jsonCredentials->access_token,
      isset($jsonCredentials->refresh_token)?($jsonCredentials->refresh_token):null,
      $jsonCredentials->created,
      $jsonCredentials->expires_in,
      Config::CLIENT_ID,
      Config::CLIENT_SECRET
  );

  return $oauthCredentials;
}
function SaveNewFile($inputFile) {
  try {
    $mimeType = 'text/plain';
    $file = new Google_DriveFile();
    $file->setTitle($inputFile->title);
    $file->setDescription($inputFile->description);
    $file->setMimeType($mimeType);
    // Set the parent folder.
    if ($inputFile->parentId != null) {
      $parentsCollectionData = new DriveFileParentsCollection();
      $parentsCollectionData->setId($inputFile->parentId);
      $file->setParentsCollection(array($parentsCollectionData));
    }
    $createdFile = $this->service->files->insert($file, array(
        'data' => $inputFile->content,
        'mimeType' => $mimeType,
    ));
    return $createdFile;
  } catch (apiServiceException $e) {
    /*
     * Log error and re-throw
     */
    error_log('Error saving new file to Drive: ' . $e->getMessage(), 0);
    throw $e;
  }
}


}
Message: Undefined index: code

Fatal error: Class 'apiClient' not found
应该是什么?我的代码做得对吗?我需要更多的代码来让它工作吗?我在GoogleAPI控制台上创建了web应用程序项目


我需要包括谷歌php sdk吗?在google文档中没有提到google drive api://

您可能正在使用旧版本的PHP客户端库。确保您拥有最新的源代码,并按照Google Drive SDK快速启动页面中的说明学习如何编写完整的PHP应用程序将文件上载到驱动器:


请使用那些require文件和Google_Client()。

Config::5112+.apps****5971157@developer.gserviceaccount.com
---这是什么?o_O@zerkms是密码,但我用***在堆栈上隐藏了真实的代码。找不到类
apiClient
。您可能忘了包含它在其中定义的文件。@Pekka说的是Google客户端库--@Pekka是的,但是这个php文件在哪里?google doc没有对Thx说任何话,现在我看到了我喜欢的错误,oauth呢?我的意思是,我不明白存储用户文件是否需要他们自己的批准,或者我只需要用我自己的帐户(站点api控制台帐户)批准,我在一个允许用户上传文件的web应用程序上,这些文件我想在GDrive上获取/发布,因此,无法理解用户是否需要在从驱动器开始上传/下载之前登录到谷歌。。farei prima in italiano mannaggia。我在api控制台中设置了一个重定向url,然后在我的脚本中使用它,但它似乎不起作用,因为oauth url表示uri不匹配:/thx,签出这可能对其他用户和mesure也有用
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();