Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have successfully fetched user profile image in my android application.Using me/posts I am able to get full_picture links in my list view.I want images in my list view.How can i achieve that?I need to have album id for fetching images from an album.How can I get album id using graph explorer.I have used this link in graph explorer.

https://graph.facebook.com/v2.3/me/albums?fields=id

but unable to fetch album id.

Graph Request

loginbtn.registerCallback(callbackmanager, new FacebookCallback<LoginResult>() {


            @Override
            public void onSuccess(final LoginResult loginResult) {
                loginbtn.setVisibility(View.GONE);
                Bundle params = new Bundle();
                params.putString("fields", "message,created_time,id,full_picture,status_type,source,comments.summary(true),likes.summary(true)");
                params.putString("limit", "10");
                GraphRequestAsyncTask data = new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/posts", params, HttpMethod.GET,
                        new GraphRequest.Callback() {
                            public void onCompleted(GraphResponse response) {
                        /* handle the result */
                                try {


                                    JSONObject jsonObject = response.getJSONObject();

                                    JSONArray jsonArray = jsonObject.getJSONArray("data");
                                     for(int i=0;i<jsonArray.length();i++) {
                                         String array=jsonArray.getString(i).toString();
                                         System.out.println(array);
                                     }

                                    System.out.println(" User timeline Messages" + jsonArray);

                                  // List data = converttoArrayList(jsonArray);  
                                    Facebook fab=jsonToFacebook(jsonArray.toString());
                                    System.out.println("Data is:-" + data);
                                    System.out.println("UserID is:-" + loginResult.getAccessToken().getUserId());
                                    ArrayAdapter<User> adapter = new ArrayAdapter<User>(MainActivity.this, android.R.layout.simple_list_item_1,fab);
                                    listviewtimeline.setAdapter(adapter);
                                } catch (JSONException j) {
                                    j.printStackTrace();
                                }

                            }
                        }
                ).executeAsync();


                //  Log.d("DEBUG",response.getJSONObject().toString());


            }


            @Override
            public void onCancel() {

            }

            @Override
            public void onError(FacebookException error) {

            }
        });
    }
    private Facebook jsonToFacebook(String result) {
        Facebook fb = null;
        if (result != null && result.length() > 0) {
            try {
                Gson gson = new Gson();
                Log.d(TAG, "jsonToFacebook: " + gson.toString());
                fb = gson.fromJson(result, Facebook.class);
            } catch (IllegalStateException ex) {
                // just eat the exception
            }
        } else {
            Log.d(TAG, "jsonToFacebook: result length is zero?: ");
        }

        return fb;
    }

User.java

public class User {
   // String s="message,created_time,id,full_picture,status_type,source,comments.summary(true),likes.summary(true)";
    @SerializedName("created_time")
    String created_time;
    @SerializedName("id")
    String id;
    @SerializedName("status_type")
    String status_type;
    @SerializedName("source")
    String source;
    @SerializedName("message")
    String message;
    @SerializedName("full_picture")
    private String full_picture;
    @SerializedName("name")
    private String name;



    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return getMessage();
    }

    @SerializedName("user")
    private FacebookUser User;
    @SerializedName("text")
    String text;

    public FacebookUser getUser() {
        return User;
    }

    public void setUser(FacebookUser user) {
        User = user;
    }



    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }







    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }





    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getCreated_time() {
        return created_time;
    }

    public void setCreated_time(String created_time) {
        this.created_time = created_time;
    }
    public String getFull_picture() {
        return full_picture;
    }

    public void setFull_picture(String full_picture) {
        this.full_picture = full_picture;
    }
    public String getStatus_type() {
        return status_type;
    }

    public void setStatus_type(String status_type) {
        this.status_type = status_type;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }


}

Facebook.java

    public class Facebook extends ArrayList<User> {
    }


FacebookUser.java

public class FacebookUser {

    @SerializedName("name")
    private String name;



    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:orientation="vertical"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="fblogin.example.com.fblogin.MainActivity">


    <com.facebook.login.widget.LoginButton
        android:id="@+id/login_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:gravity="center_horizontal"
        android:orientation="vertical">

        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/listviewtimeline"></ListView>



    </LinearLayout>
</LinearLayout>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
153 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...