代码之家  ›  专栏  ›  技术社区  ›  Devrath

提醒:Graph API v2.8将于2019年4月18日弃用。请使用API升级工具了解这可能会如何影响您的应用程序

  •  2
  • Devrath  · 技术社区  · 7 年前

    enter image description here enter image description here


    为了共同的朋友

    Bundle params = new Bundle();
                params.putString("fields", "context.fields(mutual_friends)");
                new GraphRequest(AccessToken.getCurrentAccessToken(), "/" + userProfileInfoModel.getFacebookId(), params, HttpMethod.GET,
                        new GraphRequest.Callback() {
                            public void onCompleted(GraphResponse response) {
                                facebookFriendsTagId.setText("");
                                fbFriendsApiCallForOtherFriends(response);
                            }
                        }
                ).executeAsync();
    

    我使用的代码: 用于登录

      public void getnSetUserData(AccessToken token, final Session session, final LocationResultCallback locationResultCallback){
    
            GraphRequest request = GraphRequest.newMeRequest(
                    token,
                    new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject object, GraphResponse response) {
                            Log.v("LoginActivity", response.toString());
                            try {
    
                                AccessToken token1 = AccessToken.getCurrentAccessToken();
                                String accessToken = token1.getToken().toString();
                                String expiresAt = token1.getExpires().toString();
    
                                String id = object.getString("id");
                                String gender = object.getString("gender");
    
                                String userName = object.getString("name");
    
                                String userEmail = "";
                                if(object.has("email")){
                                    userEmail = object.getString("email");
                                }
    
                                String userLocation = "";
                                String avatarURL = "";
                                String pictureURL = "";
                                try {
                                    userLocation = object.getJSONObject("location").getString("name");
                                } catch (Exception e) {
                                    userLocation = "";
                                }
                                try {
                                    avatarURL = object.getJSONObject("picture").getJSONObject("data").getString("url");
                                } catch (Exception e) {
                                    avatarURL = "";
                                }
                                try {
                                    pictureURL = "http://graph.facebook.com/" + id + "/picture/?type=large";
                                } catch (Exception e) {
                                    pictureURL = "";
                                }
    
                                UserCreationModel user = new UserCreationModel();
                                user.setId(id);
                                user.setAccessToken(accessToken);
                                user.setExpiresAt(expiresAt);
                                user.setName(userName);
                                user.setLocation(userLocation);
                                user.setEmail(userEmail);
                                user.setAvatarURL(avatarURL);
                                user.setPictureURL(pictureURL);
                                user.setGender(gender);
                                session.setUser(user);
    
                                starterInit(gender, id, userLocation,locationResultCallback);
                                //locationResultCallback.receivedLocation(id, userLocation);
                            } catch (JSONException e) {
                                EventBus.getDefault().post(new BusFacebookError(e.getMessage()));
                                e.printStackTrace();
                                System.out.println(e.toString());
                            } catch (Exception e){
                                EventBus.getDefault().post(new BusFacebookError(e.getMessage()));
                                System.out.println(e.toString());
                            }
    
                        }
                    });
    
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id, name, email, gender, location, picture.type(large)");
            //parameters.putString("fields", "id, name, email, location, picture.type(large)");
            request.setParameters(parameters);
            request.executeAsync();
        }
    

    我所做的更改:

    我把毕业证书改成了:

    implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
    

    0 回复  |  直到 7 年前