Google drive api Google Drive API推送通知可以';不能停止/取消

Google drive api Google Drive API推送通知可以';不能停止/取消,google-drive-api,google-api-nodejs-client,Google Drive Api,Google Api Nodejs Client,我正在看一个驱动器资源。设置手表(使用带有node.js和drive.file.watch的googleapis 0.2.13-alpha客户端): 如果我将node.js库与以下代码一起使用: 但我得到了同样的错误 有没有想过我可能做错了什么,或者如何调试可能出错的地方 推送通知旨在监视任何api资源,尽管它目前只支持更改和文件。因此,所有资源类型都需要唯一的resourceId。这就是他们的resourceId不等于fileId的原因 确认信息会返回到它正在查看的文件。检查您的回复的标题

我正在看一个驱动器资源。设置手表(使用带有node.js和drive.file.watch的googleapis 0.2.13-alpha客户端):

如果我将node.js库与以下代码一起使用:


但我得到了同样的错误

有没有想过我可能做错了什么,或者如何调试可能出错的地方

  • 推送通知旨在监视任何api资源,尽管它目前只支持更改和文件。因此,所有资源类型都需要唯一的resourceId。这就是他们的resourceId不等于fileId的原因

  • 确认信息会返回到它正在查看的文件。检查您的回复的标题。此外,如果需要,您可以使用令牌来保存特定于频道的信息

  • 如果您使用的是API资源管理器,则无法取消订阅该频道,因为您知道,推送通知需要通过API控制台对url进行额外验证,并且API资源管理器未通过身份验证才能访问您的通知。由于安全原因,它正在按预期工作。我将报告这个问题,以防止人们对此感到困惑

  • fileId未转到请求正文。它应该是参数之一。此外,您还应请求取消订阅。大概是这样的:

  • 订阅代码:

    var channel= {
      'id': 'yourchannelid',
      'type': 'web_hook',
      'address': 'https://notification.endpoint'
    };
    var request = client.drive.files.watch({'fileId': fileId, 'channel':channel});
    
    要取消订阅的代码

    var request = client.drive.channels.stop({'id': channelId, 'resourceId':resourceId});
    

    回答第一个问题:resourceId与fileId无关,只使用1。resourceId从Google和2返回。您提供给unsubscribe的频道id。仅供参考,频道资源已绑定到用户。如果您创建了关于用户A的资源的频道,您应该使用用户A的凭据取消订阅,否则您将获得404。用附加代码更新。如果resourceId与fileId无关,为什么resourceUrl会将fileId包含在其中?为什么确认书没有说他们在看什么文件就回来了?但是我传递了通道ID(我分配的)和资源ID(它返回的),并且得到了有问题的错误。这两个操作都是由同一个用户完成的,尽管通过两个不同的应用程序生成的两个不同的access_令牌。Re:item 2)如上所示,我使用了该令牌,因为似乎没有任何头返回被监视的文件id,我认为解析资源uri头从长远来看是不可靠的。Re:item 4)您发现了代码中的一个问题!我错误地剪切/粘贴了Bug 59,并调用了files.watch而不是channels.stop。我更新了上面的问题,以反映我尝试呼叫channels.stop的两种方式,两种方式都产生了500个错误。回复:第1项和第3项)感谢您澄清这些要点!这两种方法都是有意义的,尽管由于我经常使用API资源管理器根据我的代码进行测试,它确实会混淆一些东西。谢谢你的解释和帮助。4)你试过我发布的代码了吗?这个bug是一个已知的问题,我发布的代码是一个经过测试的解决方法。看起来这是一个bug。很快就会修好的。 'x-goog-channel-id': 'id-0ZZuoVaqdWGhpUk9PZZ-1374536746592', 'x-goog-channel-expiration': 'Mon, 22 Jul 2013 23:55:47 GMT', 'x-goog-resource-state': 'sync', 'x-goog-message-number': '1', 'x-goog-resource-id': 'WT6g4bx-4or2kPWsL53z7YxZZZZ', 'x-goog-resource-uri': 'https://www.googleapis.com/drive/v2/files/0AHuoVaqdWGhpUkZZZZ?updateViewedDate=false&alt=json', 'x-goog-channel-token': '101852559274654726533:0ZZuoVaqdWGhpUk9PZZ', 'user-agent': 'APIs-Google; (+http://code.google.com/apis)
    
    404 Not Found
    
    {
     "error": {
      "errors": [
       {
        "domain": "global",
        "reason": "notFound",
        "message": "Channel not found"
       }
      ],
      "code": 404,
      "message": "Channel not found"
     }
    }
    
    exports.cancelDriveCallbacksCmd = function( watchId, fileId, resourceId ){ var body = { id: watchId, resourceId: resourceId }; var cmd = client.drive.channels.stop( body ); return cmd; }; var cmd = exports.cancelDriveCallbacksCmd( 'id-0ZZuoVaqdWGhpUk9PZZ-1374536746592', '0ZZuoVaqdWGhpUk9PZZ', 'WT6g4bx-4or2kPWsL53z7YxZZZZ' ); var batch = client.newBatchRequest(); batch.add(cmd); batch.withAuthClient(user.auth).execute(cb); { code: 500, message: 'Internal Error', data: [ { domain: 'global', reason: 'internalError', message: 'Internal Error' } ] }
    
    exports.cancelDriveCallbacksCmd = function( watchId, fileId, resourceId ){
      var params = {};
      var body = {
        id: watchId,
        resourceId: resourceId,
        fileId: fileId
      };
    
      //var cmd = client.drive.channels.stop( params, body );
    
      // FIXME - hack around bug in RPC implementation
      var hack = {channel:body};
      for( var key in params ){
        hack[key] = params[key];
      }
      var cmd = client.drive.channels.stop( hack );
      console.log( 'cancelDriveCallbacksCmd', hack );
    
      return cmd;
    };
    
    var channel= {
      'id': 'yourchannelid',
      'type': 'web_hook',
      'address': 'https://notification.endpoint'
    };
    var request = client.drive.files.watch({'fileId': fileId, 'channel':channel});
    
    var request = client.drive.channels.stop({'id': channelId, 'resourceId':resourceId});