けれどもサイモンクロスの答えは受け入れられ、正しいされて、私は私が何をすべきかの例(アンドロイド)で少しそれをアップ牛肉だろうと思いました。私はそれをできる限り一般的に保ち、質問だけに焦点を当てます。個人的にはデータベースへの格納を完了したため、読み込みはスムーズに行われましたが、ここでは少し範囲外のCursorAdapterとContentProviderが必要です。
私は自分でここに来て、そして考えました、今何ですか?!
問題
user3594351と同様に、友達のデータが空白であることに気づきました。FriendPickerFragmentを使用してこれを見つけました。3か月前は機能していたが、機能しなくなった。Facebookの例でさえ破られました。したがって、私の問題は「FriendPickerFragmentを手動で作成するにはどうすればよいですか?」
うまくいかなかったこと
Simon Crossのオプション#1は、友達をアプリに招待するほど強力ではありませんでした。Simon Crossもリクエストダイアログを推奨しましたが、これでは一度に5つのリクエストしか許可されません。リクエストダイアログには、Facebookにログインしたセッション中に同じ友達も表示されました。役に立たない。
効果のあったもの(概要)
難しい作業を伴うオプション#2。Facebookの新しいルールを満たしていることを確認する必要があります:1.)ゲームである2.)Canvasアプリ(Webプレゼンス)を持っている3.)アプリがFacebookに登録されている。これはすべて、設定の下のFacebook開発者Webサイトで行われます。
アプリ内で手動でフレンドピッカーをエミュレートするために、次のことを行いました。
- 2つのフラグメントを表示するタブアクティビティを作成します。各フラグメントはリストを示しています。利用可能な友達のフラグメント(/ me / friends)と招待可能な友達のフラグメント(/ me / invitable_friends)。同じフラグメントコードを使用して両方のタブをレンダリングします。
- Facebookから友達データを取得するAsyncTaskを作成します。そのデータがロードされたら、値を画面にレンダリングするアダプターにそれを投げます。
細部
AsynchTask
private class DownloadFacebookFriendsTask extends AsyncTask<FacebookFriend.Type, Boolean, Boolean> {
    private final String TAG = DownloadFacebookFriendsTask.class.getSimpleName();
    GraphObject graphObject;
    ArrayList<FacebookFriend> myList = new ArrayList<FacebookFriend>();
    @Override
    protected Boolean doInBackground(FacebookFriend.Type... pickType) {
        //
        // Determine Type
        //
        String facebookRequest;
        if (pickType[0] == FacebookFriend.Type.AVAILABLE) {
            facebookRequest = "/me/friends";
        } else {
            facebookRequest = "/me/invitable_friends";
        }
        //
        // Launch Facebook request and WAIT.
        //
        new Request(
            Session.getActiveSession(),
            facebookRequest,
            null,
            HttpMethod.GET,
            new Request.Callback() {
                public void onCompleted(Response response) {
                    FacebookRequestError error = response.getError();
                    if (error != null && response != null) {
                        Log.e(TAG, error.toString());
                    } else {
                        graphObject = response.getGraphObject();
                    }
                }
            }
        ).executeAndWait();
        //
        // Process Facebook response
        //
        //
        if (graphObject == null) {
            return false;
        }
        int numberOfRecords = 0;
        JSONArray dataArray = (JSONArray) graphObject.getProperty("data");
        if (dataArray.length() > 0) {
            // Ensure the user has at least one friend ...
            for (int i = 0; i < dataArray.length(); i++) {
                JSONObject jsonObject = dataArray.optJSONObject(i);
                FacebookFriend facebookFriend = new FacebookFriend(jsonObject, pickType[0]);
                if (facebookFriend.isValid()) {
                    numberOfRecords++;
                    myList.add(facebookFriend);
                }
            }
        }
        // Make sure there are records to process
        if (numberOfRecords > 0){
            return true;
        } else {
            return false;
        }
    }
    @Override
    protected void onProgressUpdate(Boolean... booleans) {
        // No need to update this, wait until the whole thread finishes.
    }
    @Override
    protected void onPostExecute(Boolean result) {
        if (result) {
            /*
            User the array "myList" to create the adapter which will control showing items in the list.
             */
        } else {
            Log.i(TAG, "Facebook Thread unable to Get/Parse friend data. Type = " + pickType);
        }
    }
}
作成したFacebookFriendクラス
public class FacebookFriend {
    String facebookId;
    String name;
    String pictureUrl;
    boolean invitable;
    boolean available;
    boolean isValid;
    public enum Type {AVAILABLE, INVITABLE};
    public FacebookFriend(JSONObject jsonObject, Type type) {
        //
        //Parse the Facebook Data from the JSON object.
        //
        try {
            if (type == Type.INVITABLE) {
                //parse /me/invitable_friend
                this.facebookId =  jsonObject.getString("id");
                this.name = jsonObject.getString("name");
                // Handle the picture data.
                JSONObject pictureJsonObject = jsonObject.getJSONObject("picture").getJSONObject("data");
                boolean isSilhouette = pictureJsonObject.getBoolean("is_silhouette");
                if (!isSilhouette) {
                    this.pictureUrl = pictureJsonObject.getString("url");
                } else {
                    this.pictureUrl = "";
                }
                this.invitable = true;
            } else {
                // Parse /me/friends
                this.facebookId =  jsonObject.getString("id");
                this.name = jsonObject.getString("name");
                this.available = true;
                this.pictureUrl = "";
            }
            isValid = true;
        } catch (JSONException e) {
            Log.w("#", "Warnings - unable to process Facebook JSON: " + e.getLocalizedMessage());
        }
    }
}