-2

我新的Facebook的整合 在我的應用我通過Facebook登錄成功,機器人如何顯示我的Facebook好友,並邀請玩

但是,我想,

  1. 顯示我所有的Facebook好友列表與邀請按鈕邀請發送給他們

邀請

  • 我發現很多,但我不明白Facebook的文檔, 所以任何一個請給我任何相關的例子,

    非常感謝。

  • 回答

    1

    我已經把一些重要的部分用於顯示Facebook的朋友followwing。欲瞭解更多信息,您必須參考,任何quesry,

    https://developers.facebook.com/

    https://developers.facebook.com/docs/games/unity/unity-tutorial

    https://github.com/fbsamples/web-friend-smash-v1

    https://github.com/fbsamples/android-friend-smash-v2

    下面顯示FB好友列表的主要部分(即沒有安裝遊戲) 在列表中顯示Facebook朋友:

    請撥打按鈕的onClick以下功能:

     Session session = Session.getActiveSession(); 
         if (session == null || !session.isOpened()) { 
          return; 
         } 
         List<String> permissions = session.getPermissions(); 
    
         if (!permissions.contains("user_friends")) { 
    
          askForFriendsForPlayPermission(session); 
    
         } else { 
          loadFriendsFromFacebook(new FriendsLoadedCallback() { 
    
           @Override 
           public void afterFriendsLoaded() { 
            // startGame(); 
            close_button_value = 11; 
            img_close_button.setVisibility(View.VISIBLE); 
           } 
    
          }); 
    
         } 
    

    askForFriendsForPlayPermission(...):這個功能可以拿朋友的權限,如果按是那麼它顯示FB好友列表,列表中的以下內容:

    private void askForFriendsForPlayPermission(final Session session) { 
        // user has already said no once this session. 
        if (application.hasDeniedFriendPermission()) { 
        } else { 
         new AlertDialog.Builder(HomeActivity.this) 
           .setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() { 
            @Override 
            public void onClick(DialogInterface dialog, int id) { 
             // User hit OK. Request Facebook friends 
             // permission. 
              requestFriendsPermission(AUTH_FRIENDS_PLAY_ACTIVITY_CODE); 
            } 
           }).setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() { 
            public void onClick(DialogInterface dialog, int id) { 
             // User hit cancel. Keep track of deny so 
             // that we 
             // only ask once per session 
             // and then just play the game. 
             application.setHasDeniedFriendPermission(true); 
    
            } 
           }).setTitle(R.string.with_friends_dialog_title).setMessage(R.string.with_friends_dialog_message) 
           .show(); 
        } 
    } 
    

    採取user_friends權限 - 撥打:

    private void requestFriendsPermission(int requestCode) { 
        // --//--Log.d("Permiision", "Requesting friends permissions."); 
        Session.NewPermissionsRequest newFriendsPermissionsRequest = new Session.NewPermissionsRequest(this, 
          "user_friends").setRequestCode(requestCode); 
        Session.getActiveSession().requestNewReadPermissions(newFriendsPermissionsRequest); 
    
    } 
    

    負載Facebook上的朋友:

    private void loadFriendsFromFacebook(final FriendsLoadedCallback callback) { 
        final Session session = Session.getActiveSession(); 
        RequestBatch requestBatch = new RequestBatch(); 
        Request invitableFriendsRequest = Request.newGraphPathRequest(session, "/me/invitable_friends", 
          new Request.Callback() { 
    
           @Override 
           public void onCompleted(Response response) { 
    
            FacebookRequestError error = response.getError(); 
            if (error != null) { 
             Log.e(CricoApplication.TAG, error.toString()); 
             // handleError(error, true); 
            } else if (session == Session.getActiveSession()) { 
             if (response != null) { 
              // Get the result 
              GraphObject graphObject = response.getGraphObject(); 
              JSONArray dataArray = (JSONArray) graphObject.getProperty("data"); 
    
              List<JSONObject> invitableFriends = new ArrayList<JSONObject>(); 
              if (dataArray.length() > 0) { 
               // Ensure the user has at least one friend 
               // ... 
               // fb_friends = new ArrayList<String>(); 
               list_fb_friends = new ArrayList<HashMap<String, String>>(); 
               for (int i = 0; i < dataArray.length(); i++) { 
                invitableFriends.add(dataArray.optJSONObject(i)); 
                try { 
                 JSONObject json = dataArray.getJSONObject(i); 
                 String str_id = json.getString(TAG_ID); 
                 String str_first_name = json.getString(TAG_FIRST_NAME); 
    
                 JSONObject picture_obj = json.getJSONObject(TAG_PICTURE); 
                 JSONObject data_obj = picture_obj.getJSONObject(TAG_DATA); 
                 // String str_is_silhouette = 
                 // data_obj.getString(TAG_IS_SILHOUETTE); 
                 String str_url = data_obj.getString(TAG_URL); 
    
        // put fb id and friends name in map and add to list view 
                 map_fb_friends = new HashMap<String, String>(); 
                 map_fb_friends.put("str_id", str_id); 
                 map_fb_friends.put("str_first_name", str_first_name); 
                 map_fb_friends.put("str_url", str_url); 
                 list_fb_friends.add(map_fb_friends); 
                 fb_friends.add(str_id); 
    
                } catch (Exception e) { 
                 e.printStackTrace(); 
                } 
               } 
    
    
    LazyAdapter_fb_friends adapter = new LazyAdapter_fb_friends(HomeActivity.this, 
                 list_fb_friends); 
    Your_list_view.setAdapter(adapter); 
              } 
    
              application.setInvitableFriends(invitableFriends); 
             } 
            } 
           } 
    
          }); 
        Bundle invitableParams = new Bundle(); 
        invitableParams.putString("fields", "id,first_name,picture"); 
        invitableFriendsRequest.setParameters(invitableParams); 
        requestBatch.add(invitableFriendsRequest); 
    
        // Get the user's list of friends. 
        // This only returns friends who have installed the game. 
        Request friendsRequest = Request.newMyFriendsRequest(session, new Request.GraphUserListCallback() { 
    
         @Override 
         public void onCompleted(List<GraphUser> users, Response response) { 
          FacebookRequestError error = response.getError(); 
          if (error != null) { 
           Log.e(CricoApplication.TAG, error.toString()); 
           // handleError(error, true); 
          } else if (session == Session.getActiveSession()) { 
           // Set the friends attribute 
           application.setFriends(users); 
           callback.afterFriendsLoaded(); 
          } 
         } 
        }); 
    

    您可以使用facebook-id邀請特定的朋友。

    1

    希望this將幫助你。
    如果你想顯示你所有的朋友,那麼你要合併兩個API

    1. 誰不使用你的應用程序,他們可以通過調用圖形API invitable_friends here得到的朋友是代碼的文檔。
      (invitable_friends只能得到,如果你FBApp 分類遊戲)誰已經在使用你的應用程序,他們可以通過調用圖形API的朋友

    這裏得到的,如果你想

  • 友要檢索invitable_friends,那麼你必須login with permission

    然後在這裏發送邀請的最後一件事是documentation