Gcloud pubsub - how to create a view request

I created a theme by subscribing to it, set the publish permissions of the theme using Google API Explorer and now you need to create a view request as described here: https://developers.google.com/gmail/api/guides/push

However, according to previous threads, you cannot do this using API Explorer and must do it directly from gcloud. I know that the general form of a call is something like:

POST "https://www.googleapis.com/gmail/v1/users/me/watch"
Content-type: application/json

{
  topicName: "projects/myproject/topics/mytopic",
  labelIds: ["INBOX"],
}

      

However, I'm not sure how to implement this in node.js - what does the code look like? I tried the following but I get the error function undefined

:

gcloud.watch({  "topicName":
"projects/pipedrivesekoul/topics/my-new-topic",  "labelIds": [  
"INBOX"  ] })

      

Any help is greatly appreciated!

+3


source to share


3 answers


yep you need to use the Gmail API to set up the watcher, see example below. You need to set up "oauth2Client" before doing this yourself, I assume you have that. If you use a google-enabled login on your website, you already have one.



var options = {
    userId: 'me',
    auth: oauth2Client,
    resource: {
        labelIds: ['INBOX'],
        topicName: 'projects/id/topics/messageCenter'
    }
};

gmail.users.watch(options, function (err, res) {
    if (err) {
        // doSomething here;
        return;
    }
    // doSomething here;
});

      

+3


source


Unfortunately it is not supported by gcloud-node. The gmail API can be used in the API: https://developers.google.com/apis-explorer/#p/gmail/v1/



+2


source


If all else fails, you can just do a POST request, eg. request , for example:

var request = require('request');

request({
  url: "https://www.googleapis.com/gmail/v1/users/me/watch",
  method: "POST",
  headers: {
    Authorization: 'Bearer {YOUR_API_KEY}'
  },
  data: {
    topicName: "projects/pipedrivesekoul/topics/my-new-topic",
    labelIds: ["INBOX"]
  },
  json: true
}, function(response) {
  console.log(JSON.stringify(response, null, 4));
});

      

+2


source







All Articles