2017-03-10 5 views
0

google/apiclientを使用して個人アカウントから自分のファイルをリストしようとすると成功できません。私の手順(下記のコード)を接続するには、Google APIクライアントを使用して(サービスアカウントのではなく、クライアントの代理)キー GoogleドライブAPIへの無断アクセス

  • をダウンロード

    1. 作成したサービスアカウント
    2. 有効ドメイン委任

    初期化と上場

    private function _initClient(string $keyLocation) 
    { 
        if (empty($keyLocation) || !file_exists($keyLocation)) 
        { 
         throw new \Exception("Missing google certificate file"); 
        } 
    
        $client = new \Google_Client(); 
        $client->setApplicationName('My App'); 
        $client->useApplicationDefaultCredentials(); 
        $client->setSubject("[email protected]"); 
        $client->setScopes([ 
         'https://www.googleapis.com/auth/drive', 
        ]); 
        return $client; 
    } 
    
    public function listDirectories() 
    { 
        $drive = new \Google_Service_Drive($this->client); 
        $files = $drive->files->listFiles([ 
         'corpus' => 'user', 
         'spaces' => 'drive' 
        ]); 
    
    
        var_dump($files); 
    
    } 
    
    
    require_once 'vendor/autoload.php'; 
    $key = __DIR__.DIRECTORY_SEPARATOR.'client_id.json'; 
    putenv('GOOGLE_APPLICATION_CREDENTIALS='.$key); 
    $t = new Myclass($key); 
    $t->listDirectories(); 
    
    01応答で

    私が取得:

    Uncaught Google_Service_Exception: { "error": "unauthorized_client", "error_description": "Client is unauthorized to retrieve access tokens using this method." } だから、主な問題は、私が行方不明です何ですか?委任されたアカウントの事前承認が可能な場所または、ユーザー確認なしにDrive APIと通信する別の方法がありますか?あなたがドメインgmail.comの所有者ではないので、あなたが@ gmail.comのためのドメイン全体の代表団(DWD)を有効にすることはできません

  • 答えて

    0

    を占めています。 DWDは、G Suiteアカウントでのみ使用できます。 gmail.comアカウントについては、別の方法をとる必要があります。詳細についてはthis documentationをご覧ください。

    要約すると、これはユーザーの同意なしに行うことはできません。この情報が役立つことを願っています。

    関連する問題