googleapis / googleapis/google-api-nodejs-client
gmail.users.watch | error sending test message to Cloud PubSub projects/tms-erp-afourtech-assets/topics/gmail-watcher : User not authorized to perform this action.
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 12.3k
- Forks
- 2k
- Ø Merge
- 1 T. 9 Std.
- Gemergte PRs (30 T.)
- 24
Beschreibung
I want to implement watch for new mails in INBOX for a Google Workspace email ID.
Already Verified Pointers:
- I've made sure that
client_idfromservice.jsonfile has domain wide delegated authorisation for the scope being used. - I've also made sure that service account has
Publisheraccess. - I've also made sure that
client_emailhasPublisheraccess from thePub/SubFollowed this solution
Still getting
{
message: 'Error sending test message to Cloud PubSub projects/<PROJECT_ID>/topics/gmail-watcher : User not authorized to perform this action.',
domain: 'global',
reason: 'forbidden'
}
Code:
import { google, Auth } from 'googleapis';
import { resolve } from 'path';
const serviceAccountPath = resolve('./service.json')
const scopes = [
'https://www.googleapis.com/auth/gmail.metadata'
]
const emailToBeDelegated = 'email.id@domain.com'
class GoogleAuth {
public auth;
constructor(serviceAccountPath: string, scopes: string[], emailToBeDelegated: string){
this.auth = this.getAuth(serviceAccountPath, scopes, emailToBeDelegated);
}
public async getAuthorizedJWT () {
await this.auth.authorize();
return this.auth;
};
private getAuth = (serviceAccountPath: string, scopes: string[], emailToBeDelegated: string): Auth.JWT => {
return new Auth.JWT({
keyFile: serviceAccountPath,
scopes,
subject: emailToBeDelegated
});
};
}
class GMailService extends GoogleAuth {
constructor(serviceAccountPath: string, scopes: string[], emailToBeDelegated: string){
super(serviceAccountPath, scopes, emailToBeDelegated);
}
watch = async () => {
const auth = await this.getAuthorizedJWT();
return google.gmail({ version: 'v1' }).users.watch({auth,
userId: 'me',
requestBody: {
topicName: 'projects/<PROJECT_ID>/topics/gmail-watcher',
labelIds: ['INBOX']
}
})
}
}
(async () => {
const gMailService = new GMailService(serviceAccountPath, scopes, emailToBeDelegated);
console.log(await gMailService.watch());
})();
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der im Issue gezeigten Methode GMailService.watch sowie den Methoden GoogleAuth.getAuth/getAuthorizedJWT. Reproduziere die users.watch-Anfrage mit dem angegebenen Gmail-Scope und Pub/Sub-Topic und ermittle anschließend, welche Autorisierungsgrenze sie ablehnt; abgeschlossen ist die Aufgabe, wenn eine bestätigte Ursache und eine reproduzierbare Lösung identifiziert wurden, da keine Repository-Datei oder kein Test genannt ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- api, authentication, cloud
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 20/100