2

私はIONICアプリケーションに取り組んでいます。このアプリでは、ユーザーは自分のGoogle フォトアカウントから写真を取得し、選択した画像に対してデザイン操作を行うことができます。

そのためにGoogle Photos APIを使いたい

IONIC でこれを達成する方法の例は見つかりませんでした。

そのため、これを行う方法についてサンプルコードまたはGUIDを探しています。

================================================== =====

アップデート

私はこのようにそれをやろうとしました:

次を使用して Google にログインし、 スコープ をcordova-plugin-googleplus
リクエストし ます。コードは次のとおりです。https://www.googleapis.com/auth/photoslibrary

//Here we do a login.
this.gplus.login({
   'webClientId': '***********',
   'offline': true,
   'scopes': 'profile email https://www.googleapis.com/auth/photoslibrary'
}).then((res) => {
   //after login we try to get the google photos albums
   this.http.get('https://photoslibrary.googleapis.com/v1/albums', {
      responseType: ResponseContentType.Json,
      params:{
         accessToken: res.accessToken,
         pageSize: 50,          
      }
   }).subscribe(res=>{
      console.log('<--- google images res: ', res);
   },err=>{
      console.log('<--- google images err: ', err);
   });
});

ここで、「Expected OAuth 2 access token」というエラーが 表示され
ます。エラーの完全な説明は次のとおりです。

Request is missing required authentication credential. 
Expected OAuth 2 access token, login cookie or other valid authentication credential. 
See https://developers.google.com/identity/sign-in/web/devconsole-project.

================================================== ========

更新 2

したがって、いくつかの調査の後、次のような OAuth 2 アクセス トークンを取得しようとしています。

//Here we do a login.
this.gplus.login({
   'webClientId': '***********',
   'offline': true,
   'scopes': 'profile email https://www.googleapis.com/auth/photoslibrary'
}).then((res) => {
   //after login we need to get the OAuth 2 access
   //I think like this:
   this.http.post('https://www.googleapis.com/oauth2/v4/token', {
      code: res.serverAuthCode,
      client_id: '*****************',
      client_secret: '*************',
      redirect_url: '***************',
      grant_type: 'authorization_code'
   },{
      responseType: ResponseContentType.Json
   }).subscribe(res=>{
      //after we got the OAuth 2 access, we try to get the google photos albums
      let myHeaders= new Headers();
      myHeaders.append('Content-Type', 'application/json');

      this.http.get('https://photoslibrary.googleapis.com/v1/albums', {
         responseType: ResponseContentType.Json,
         params:{
            pageSize: 50,    
            accessToken: {'bearer': res['_body'].access_token},
          },
          headers: myHeaders
        }).subscribe(res=>{
          console.log('<--- google images res: ', res);
        },err=>{
          console.log('<--- google images err: ', err);
        })
   },err=>{
      ......
   })
  }  
}), err => {
   .....
});

しかし、それでも同じエラーが発生します:

Request is missing required authentication credential. 
Expected OAuth 2 access token, login cookie or other valid authentication credential. 
See https://developers.google.com/identity/sign-in/web/devconsole-project.

では、問題はOAuth 2 アクセス トークンを取得する方法です。

4

0 に答える 0