1

Does a link to a facebook profile picture stay up to date or should I store images in storage?

I am using firebase and facebook authentication and grabbing a users profile picture link like this when they FIRST create an account:

const photoLarge = await getFacebookUserInfo().then((userResponse) => {
                return userResponse.picture.data.url.toString()
              }).catch((error) => {
                return error
              });   
            const userId = await firebaseService.auth().currentUser.uid;
            writeUserData(
              userId,
              photoLarge,
            );
          }

For some reason I noticed in dev vs prod I have 2 different links with the dev not working.

Dev doesn't work:

https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=10161383578450224&height=200&width=200&ext=1558132998&hash=AeTUIkafEn5zw5PF

Prod Does:

https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=10161383578450224&height=200&width=200&ext=1558673410&hash=AeQGA8guHyxIK9du

I am trying to figure out if the facebook picture should be downloaded and stored in storage and then referenced instead and if so how to go about doing that? (/ is there a expiration date on a link)

I haven't seen if this is happening or not for Google Sign-in.

Here is my graph request:

//graph QL request to get larger facebook profile
export const getFacebookUserInfo = () => {
  return new Promise((resolve, reject) => {
    const infoRequest = new GraphRequest(
      '/me',
      {
        parameters: {
          fields: {
            string: 'email,about,name,picture.type(large)'
          }
        }
      },
      (error, data) => {
        if (error) {
          reject(error);
        } else {
          resolve(data);
        }
      }
    );
    new GraphRequestManager().addRequest(infoRequest).start();
  })
}
Stephen Phillips
  • 641
  • 10
  • 26
  • user's could delete or change their profile pictures from profiles. when this happen probably their profile picture links gonna be broken. if you have limited storage you could search if any method exists to getting their profile pictures by their usernames (it contains in user profile link) – Cem Kocagöz May 24 '19 at 04:29
  • 1
    You can always use the API endpoint that just redirects to the real picture location - then it will automatically be up-to-date even when the CDN URLs change. https://developers.facebook.com/docs/graph-api/reference/user/picture – 04FS May 24 '19 at 06:30
  • I forgot to add in the graphQL request I wrote, but added it in to the code above. Is the code added above doing the same thing you mentioned? – Stephen Phillips May 24 '19 at 17:45

1 Answers1

4

So somehow I finally figured this out today. Essentially the graphAPI spits back several pieces with one being a picture piece. This looks like the links I posted above https://platform-lookaside.fbsbx.com/platform/profilepic

THIS CHANGES!!! Not sure how often, but do NOT use this as eventually it will be a dead link.

However, what I missed was that you can use the ID that the graphAPI spits back instead and use the following link:

http://graph.facebook.com/{your_id_goes_here}/picture?type=large&redirect=true&width=500&height=500

More information can be found in this other post:

Get user profile picture by Id

Stephen Phillips
  • 641
  • 10
  • 26