Google plus (Get the URL of the picture)

I am stuck with the problem of getting the image URL as a response from Google Plus.

Signed exactly what I need.

{
 "id": "ID",
 "name": "NAME",
 "given_name": "GiVEN NAME",
 "family_name": "FAMILY_NAME",
 "link": "https://plus.google.com/ID",
 "picture": "https://PHOTO.jpg",
 "gender": "GENDER",
 "locale": "LOCALE"
}

Until then, I have been using the following to get the same. please take a look.

Using undermentioned in onConnected ();

try {
                 URL url = new URL("https://www.googleapis.com/oauth2/v1/userinfo");
                  //get Access Token with Scopes.PLUS_PROFILE
                  String sAccessToken;
                sAccessToken = GoogleAuthUtil.getToken(MainActivity.this,
                                          mPlusClient.getAccountName() + "",
                                          "oauth2:" + Scopes.PLUS_PROFILE
                                          + " https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email");

                   HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
                      urlConnection.setRequestProperty("Authorization", "Bearer "
                              + sAccessToken);
                      BufferedReader r = new BufferedReader(new InputStreamReader(
                              urlConnection.getInputStream(), "UTF-8"));
                      StringBuilder total = new StringBuilder();
                      String line;
                      while ((line = r.readLine()) != null) {
                          total.append(line);
                      }
                      line = total.toString();
                      System.out.println("::::::::::::::::::::::::" + line);
            } catch (UserRecoverableAuthException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Intent recover = e.getIntent();
                startActivityForResult(recover, REQUEST_AUTHORIZATION);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (GoogleAuthException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

Result of the above ::

{ "id": "106193796000956371669", "email": "vivek@xyz.com", "verified_email": true, "name": "Vivek Singh", "given_name": "Vivek", "family_name": "Singh", "link": "https://plus.google.com/10619379600095669", "gender": "male", "locale": "en", "hd": "xyz.com"}

Please report what I do not see. Any suggestion could be helpful to me.

Thanks!

0
source share
3 answers

You can make a request to get the profile picture directly if you know the user ID that you can get from your code.

Just call

https://plus.google.com/s2/photos/profile/" + user.getGooglePlusId() + "?sz=100

getGooglePlusId() - , sz .

EDIT:

( 2015 ) https://www.googleapis.com/plus/v1/people/{GOOGLE_USER_ID}?key={YOUR_API_KEY} :

GOOGLE_USER_ID - Google Plus

YOUR_API_KEY - API Android ( , )

JSON, "". . .

, API 10000 . google api Google , , .

+4

ImageView .

. user_picture

, .. @For Facebook/Google Plus

if(usertype.equalsIgnoreCase("facebook")){

            try{

                URL img_value = null;
                img_value = new URL("http://graph.facebook.com/"+ userProfileID +"/picture?type=square");
                Bitmap mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
                user_picture.setImageBitmap(mIcon1);

            }catch(Exception e){
                e.printStackTrace();
            }

        }else{

            try{

                URL img_value = null;
                img_value = new URL("https://plus.google.com/s2/photos/profile/"+ google_Plus_User_Id +"?sz=50");
                Bitmap mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
                user_picture.setImageBitmap(mIcon1);

            }catch(Exception e){
                e.printStackTrace();
            }

        }

, -. !

-1
$forJson = file_get_contents('http://picasaweb.google.com/data/entry/api/user/'.$userInfo['id'].'?alt=json', true);
$withowtBacs = str_replace('$','',$forJson);
$toArr = (array)json_decode($withowtBacs);
$andNext = (array)$toArr[entry];
$imgPath = (array)$andNext[gphotothumbnail];
$this->session->set_userdata('imgPath', $imgPath[t]);
-1
source

Source: https://habr.com/ru/post/1524979/


All Articles