简体   繁体   中英

Facebook Graph API - How to avoid request limits when accessing a user's photos?

I need to fetch user photos and albums using the Facebook Graph API.

As far as I understand (while reading the docs) this is a two step procedure, 1. fetching the id for each photo from the photos edge, 2. using the returned array of ids, fetching individual photo nodes.

Fetching individual photo nodes could mean hundreds of requests/s, while having a lot of photos on my profile I have hit the app request limits after a few minutes of testing.

Is there maybe a way to fetch all photos at once (or in fewer requests), in order to avoid request limits?

example implementation:

  ...

  var photos = [];

  function fetchPhotos(){
    fetch('https://graph.facebook.com/v3.1/me/photos?type=uploaded&access_token=' + accesstoken, {
      method: 'GET'
    })
    .then(photos => photos.json())
    .catch(error => console.error('Error:', error))
    .then(photos => {

      this.fetchPhoto(photos);

    });
  }

  function fetchPhoto(photos){
    for(var i=0; i < photos.data.length; i++){
      fetch('https://graph.facebook.com/v3.1/' + photos.data[i].id + '?fields=link,width,height&access_token=' + accesstoken, {
        method: 'GET'
      })
      .then(photo => photo.json())
      .catch(error => console.error('Error:', error))
      .then(photo => {

        photos.push(photo);

      });
    }
  }

  ...

Thanks!

You can already get a list with all the fields with one call:

https://graph.facebook.com/v3.1/me/photos?fields=link,width,height&access_token=...

Side Note: If that is client code, why not use the official JS SDK? That way, you don´t need to deal with the Access Token, it gets added automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM