I am exploring the Google Cloud PubSub these days. I am working on a project where I have to listen for the User's Gmail Inbox and then process the new emails as they arrive.
I used a Gmail Client API to add the watch on user's Gmail. I encountered the following exception
I used a Gmail Client API to add the watch on user's Gmail. I encountered the following exception
Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Invalid topicName does not match projects/modular-botany-234216/topics/*",
"reason" : "invalidArgument"
} ],
"message" : "Invalid topicName does not match projects/modular-botany-234216/topics/*"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
Solution
After a bit of struggle and google, I found that I have created the credentails.json file for another project instead of the one I was using in the watch call
WatchRequest watchRequest = new WatchRequest();
List<String> labels = new ArrayList<String>();
labels.add("INBOX");
watchRequest.setLabelIds(labels);
watchRequest.setTopicName("projects/modular-botany-234216/topics/GmailMessage");
STEP 1
Open the credentails page i.e. https://console.developers.google.com/apis/credentials
STEP 2
Select the Project from the list
STEP 3
STEP 4
- Enter the Name
- Authorized Redirect URLs
You are done.
Comments
Post a Comment