Chris
Chris

Reputation: 4728

Getting albums from Facebook using ionic-native/facebook

I am using the ionic-native/facebook plugin to get the albums for users who have authorised my app.

After a user has clicked the "log in with facebook" link in the app they are taken to Facebook, they approve the app and then get sent back. At this point I make an API call to get their albums:

this.fb.api('/me/?fields=id,name,albums{name,picture,cover_photo{images}}', this.fbPermisions)
.then((res: any) => {
  console.log(res);
})
.catch(this.handleError);   

This returns an error in the console: Error processing action - "There was an error making the graph call"

If however I try either of the following calls then they successfully execute.

this.fb.api('/me', this.fbPermisions)
.then((res: any) => {
  console.log(res);
})
.catch(this.handleError);

Or

this.fb.api('/me/?fields=id,name,albums', this.fbPermisions)
.then((res: any) => {
  console.log(res);
})
.catch(this.handleError);    

All three calls work absolutely fine if I use the Graph API Explorer.

So, does anybody know why /me/?fields=id,name,albums{name,picture,cover_photo{images}} fails within ionic-native/facebook but works via the Graph API Explorer?

Upvotes: 0

Views: 243

Answers (1)

Chris
Chris

Reputation: 4728

It seems like urlencoding the request gives me what I need.

So instead of:

this.fb.api('/me/?fields=id,name,albums{name,picture,cover_photo{images}}', this.fbPermisions)

I used:

this.fb.api('/me/?fields=id%2Cname%2Calbums%7Bname%2Cpicture%2Ccover_photo%7Bimages%7D%7D', this.fbPermisions)

And voila, it worked .. !

Upvotes: 1

Related Questions