2016-07-26 6 views
2

私はconsole.developers.google.comでサービスアカウントを作成しており、そのサービスのクライアントIDをadmin.googleに追加しました詳細設定>認証> OAuthクライアントアクセスの管理で、ドメイン全体の委任のために.comを使用します。 Google Nodejs api clientGoogle Nodejs auth libraryを使用してGoogleドライブのfile.updateが2つの脚注付きのoauthで正常に動作しますが、正常に動作しません

は、私はその後、使ってJWTクライアントを作成しました:

const jwtClient = new google.auth.JWT(
     key.client_email, 
     null, 
     key.private_key, 
     [ 
      'https://www.googleapis.com/auth/spreadsheets', 
      'https://www.googleapis.com/auth/drive', 
      'https://www.googleapis.com/auth/drive.file', 
      'https://www.googleapis.com/auth/drive.appdata', 
      'https://www.googleapis.com/auth/drive.scripts', 
      'https://www.googleapis.com/auth/drive.metadata' 
     ], 
     '[email protected]' 
); 

const google = require('googleapis'); 
const sheets = google.sheets('v4'); 
const drive = google.drive('v3'); 

と私はから

async.waterfall(
    [ 
     (callback) => { 
      sheets.spreadsheets.create(
       { 
        auth: jwtClient, 
        resource: { 
         properties: { 
          title: 'Testing' 
         } 
        } 
       }, 
       (err, spreadsheet) => { 
        console.log(spreadsheet); 
        callback(err, spreadsheet.spreadsheetId) 
       } 
      ) 
     }, 
     (spreadsheetId, callback) => { 
      drive.files.update(
       { 
        auth: jwtClient, 
        fileId: spreadsheetId, 
        resource: { 
         addParents: config.folder 
        } 
       }, 
       (err, file) => { 
        console.log(file); 
        callback(err, file); 
       } 
      ) 
     } 
    ], 
    (err, results) => { 
     if (err) { 
      console.log(err); 
      res.status(400).send({ error: err.toString() }); 
     } else { 
      res.status(200).send("It lives!"); 
     } 
    } 
); 

私の応答を実行しましたfile.updateの2回目の呼び出しでは、200とファイルの応答が返されます。

{ kind: 'drive#file', 
    id: '<id-here>', 
    name: 'Testing', 
    mimeType: 'application/vnd.google-apps.spreadsheet' } 

しかし、不思議なこと... addParentsは、ドライブのWebアプリケーション上のファイルの内容には反映されません。

アイデア私はGoogleのapisサポートに連絡しており、約1週間でどこにもいらない。あなたの助けを前もって多くの感謝します!

答えて

0

問題は、addParentsがファイルパラメータのフィールドではなく、クエリパラメータであることです。このように、それはfileIdのピアとして指定する必要があります。

drive.files.update(
    { 
     auth: jwtClient, 
     fileId: spreadsheetId, 
     addParents: config.folder 
    }, 
    ... 
+0

ありがとうございました!これは私の問題でした。スーパーは助けを感謝する! – cdbattags

+0

[スタックオーバーフローのガイドライン](http://stackoverflow.com/help/someone-answers)に従って、正しい場合は答えを受け入れてください。 –

+0

おっと、私がコメントしたときにやったと思った。ごめんなさい! – cdbattags

関連する問題