Search code examples
facebookfirebasereact-nativefacebook-graph-apifacebook-javascript-sdk

Facebook Profile Picture Link Changes?


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();
  })
}

Solution

  • 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