2

I am trying to get the full size image from google using passport Google Oauth.

I see from other questions that the small size is coming from the "/photo.jpg?sz=50'" at the end of the url string.

since i don't think there is a way to ask for the full size on initial load, what would be the way to remove that part of the url before it gets saved to the database.

One person said to put:

 iamgeUrl=user[image][url].substr(0,user[image][url].indexOf('?str=')) + '?sz=100';

but not sure where that would go in my code...

    passport.use(
  new GoogleStrategy(
    {
      // options for google strategy
      clientID: process.env.googleclientID,
      clientSecret: process.env.googleclientSecret,
      callbackURL: "/auth/google/redirect"
    },
    (accessToken, refreshToken, profile, done) => {
      console.log(accessToken, refreshToken, profile)
      // check if user already exists in our own db
      User.findOne({ googleId: profile.id }).then(currentUser => {
        if (currentUser) {
          // already have this user
          done(null, currentUser);
        } else {
          // if not, create user in our db
          new User({
              googleId: profile.id,
              username: profile.displayName,
              thumbnail: profile._json.image.url,
              firstName: profile.name.givenName,
              lastName: profile.name.familyName,
              email: profile.emails[0].value,



          })
            .save()
            .then(user => {

              console.log("created new user: ", user);
              done(null, user);
            });
        }
      });
    }
  )
);
denis
  • 159
  • 9
  • Please post the solution as an answer, don't add it to the question. – JJJ Dec 06 '18 at 15:20
  • Don't write the solution in a comment. Post it as a new answer. – JJJ Dec 06 '18 at 17:52
  • I just used url.split('?'); cause I dont want to rely on '=' and sz=50 could be changed 1 day, so I remove all the query params this way – Roee Mar 06 '19 at 20:32

1 Answers1

4

I figured it out. Just have to replace the "sz-50" with an empty string, when it gets called.

      const ImgUrl = profile._json.image.url.replace("?sz=50", "")
  // if not, create user in our db
  new User({
      googleId: profile.id,
      username: profile.displayName,
      thumbnail: ImgUrl,
      firstName: profile.name.givenName,
      lastName: profile.name.familyName,
      email: profile.emails[0].value,



  })
denis
  • 159
  • 9