我已经创建了一个统一的应用程序来登录使用谷歌和访问谷歌教室api。登录是成功的,范围也允许进入课程。
问题:如何在使用firebase登录后查询。端点:https://classroom.googleapis.com/v1/courses/105459102203方法:获取参数: CourseId,我已经有了
BearerToken:如何从防火墙中检索?
当我尝试使用auth代码和/或idToken时,会出现以下错误:
{“错误”:{“代码”:401,“消息”:“请求具有无效的身份验证凭据。预期的OAuth 2访问令牌、登录cookie或其他有效的身份验证凭据。参见https://developers.google.com/identity/sign-in/web/devconsole-project。”,“状态”:“未经身份验证”}}
提前谢谢。
发布于 2020-11-02 20:30:25
有许多方法可以通过firebase成功地发出API请求,尤其是Google:
headers: new HttpHeaders(
{
'Content-Type': 'application/json',
Authorization: `Bearer [${this.user$.AccessToken}]`
})这就是我所称的困难方式,因为您必须确保传递和刷新每个API服务的令牌。
declare var gapi;
/** Initialize Google API Client */
initClient(): void {
gapi.client.init({
apiKey: environment.firebaseConfig.apiKey,
clientId: environment.firebaseConfig.clientId,
discoveryDocs: environment.firebaseConfig.discoveryDocs,
scope: environment.firebaseConfig.scope,
});
}
/** Do a OAuth login and then pass it to a FirebaseAuth service */
async login() {
const googleAuth = gapi.auth2.getAuthInstance();
const googleUser = await googleAuth.signIn();
const token = googleUser.getAuthResponse().id_token;
const credential = firebase.auth.GoogleAuthProvider.credential(token);
await this.afAuth().signInAndRetrieveDataWithCredential(credential);
}
/** Then you're ready to make a request*/
/**
* Lists all course names and ids.
* Print the names of the first 10 courses the user has access to. If
* no courses are found an appropriate message is printed.
*/
listCourses() {
this.courses$ =
gapi.client.classroom.courses.list({pageSize=10;}).then(response => {
return from<Course[]>(response.result.courses);
});
}https://stackoverflow.com/questions/62115572
复制相似问题