How to like facebook messages - android

In my application I have one expandable list view which displays Facebook messages.
When a user clicks the list view then a child view opens in that I have a button called Like. By clicking the Like button the original message should be liked in Facebook
One important thing is that it should not ask login details from the user. I searched a lot on the web but I find any good tutorial.
I don't have any basic idea of Facebook. Please provide me with some suggestions of how to do it.
Thanks

Well, if you want to like Facebook messages, you need to ask a permission for that with the Facebook SDK :
https://github.com/facebook/facebook-android-sdk
So Basically, you can do SSO with Facebook SDK, he will just ask for the permission needed if the user is already logged on his Facebook application.
Take a look at the sample on the Android SDK Facebook on the link above.
When you have the "like" permission (publish_stream), you can do it like that :
Request likeFacebook = new Request(Session.getActiveSession(), fBPostId + "/likes", null, HttpMethod.POST, new Request.Callback() {
#Override
public void onCompleted(Response response) {
// analyse your response
}
});
Request.executeBatchAndWait(likeFacebook);

Related

How to dev/test android app with Facebook sdk - while my app is not completed and not ready for review?

I'm developing android app which integrates Facebook SDK.
I need to login - OK, done this.
I need to retrieve friends birthdays - I know it is restricted. But can it be allowed after app review?
Or how to retrieve my friends list and birthday of each friend?
Thank you.
EDIT:
It looks strange to me that when using Facebook Graph API Explorer I do friend list request (e.g. graph.facebook.com/1012984682046884/friends) I'm getting full list of my friends. But when I do the same request from android application (see code below), I'm getting result: onCompleted resp[{"summary":{"total_count":228},"data":[]}]
Here is list of permission I'm requesting during login:loginButton.setReadPermissions(Arrays.asList("public_profile", "email", "user_birthday", "user_friends"));Also, have to tell that I am admin of my FB app, I use the same FB login.
GraphRequest request = GraphRequest.newGraphPathRequest(
act,
fbuid+"/friends",
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse response) {
// Insert your code here
Log.d("12x17","onCompleted resp["+response.getRawResponse()+"]");
}
});
request.executeAsync();
Or how to retrieve my friends list and birthday of each friend?
By making each friend log in to your app, and having them grant your app permission to access their friends, and their birthday.
No, there is no other way. You can not get friends that are not users of the same app, and you can not get a person’s birthday unless they personally grant permission.
If your app hasn't been approved yet by Facebook to retrieve that information through the Graph API you will only be able to retrieve the information for people on your friends list that are listed as Administrators, Developers, or Testers on your Facebook app developers page. Add a trusted friend or 2 to one of those categories and you should be able to retrieve that information

Accessing photos with facebook 4.4.1 SDK for android

I'm just starting out with android development and using the Facebook SDK. I have followed online tutorials and successfully made an app that logs into facebook and now im trying to make an app that creates a new activity showing the profile picture of the user after logging in.
I'm trying to follow the facebook documentation for using the SDK however it is rather vague and I was hoping to find a better example. All I can find is the following example code:
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/{user-id}/photos",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
).executeAsync();
I'm fine with all the access token stuff but I have no idea how to handle the result. How can save the images from "response" and how can I display these images in a new activity? A link to a relevant example would be really helpful. I've been looking for hours and found nothing related recent versions of the SDK.

Get facebook albums and album images?

Hello Friends
I am trying to get facebook album of a user . Problem is that it is returning albums for the user who is created the facebook app or who is the admin of that application .
For rest of the users it is returning the empty array
new Request(session, "/me/albums", null, HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
System.out.println("Responce "
+ response.getGraphObject());
}
}).executeAsync();
This work for me because i have create a facebook app and for the rest of the users it is not returning the data. Please let me know how to resolve this.
Thanks
Amit
When your application is in sandbox/development mode you can not perform any api call for other user. To test your for other user, add the user as a tester, developer or admin. See details here
Since you probably ask for the user_photos permission already (else it would not work for the admin), there are two possible problems why it does not work for other users:
Your App is in not set public. Go to the "Status & Review" tab of your App settings and make sure that checkbox on top says "YES".
Most permissions (like user_photos) need to get reviewed by Facebook before you can use them for any other user: https://developers.facebook.com/docs/apps/review/login

Which permissions I need to read Facebook App Users List

I need list of users which are using my Facebook App. So I am sending below Request.
new Request( session, "/me/friends", null, HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
...});
Fo that which permissions I need to set in facebook app?
According to Graph API user_friends permission is required. But I cant find this permission anywhere in my app.
I was using "read_friendlists" permission but FB rejected it.
Reply from Facebook Review team :
read_friendlists
Android
It looks like you're trying to use read_friendlists for something it cannot do. This permission doesn't show you a list of a person's friends.
Read_friendlists gives access to the names of custom lists a person has created to organize their friends. It will not help you invite a person's friends to use your app. To learn more about how to invite friends to an app, please see our FAQs.
Please remove "read_friendlists" from your submission. Learn more here.
The user_friends permission is the right one to use. Keep in mind that /me/friends will only return the friends which are using the same app, not all friends.
See
Get facebook friends with Graph API v.2.0
https://developers.facebook.com/docs/facebook-login/permissions/v2.2#reference-user_friends

How to integrate Facebook SDK into Native Android apps

Facebook has a very good documentation of integrating SDKs for Android, iOS & JavaScript etc. But still I have seen some confusions or misunderstandings regarding the exact ways to integrate Facebook SDK.
So I am writing all to the point steps to integrate Facebook SDK in Android Native apps and make use of Graph APIs etc.
In documentation, they have explained it in the way of documentation.
Here I am trying to explain the steps the way we need them while integrating in our app.
I will be giving answers to the most doubts we get, most occurring errors etc.
I hope it will help someone someday.
Facebook provides a wide range of options that can be done by integrating its SDK. But we need to follow some proper steps for the same.
Login
The very first thing we need to do is Login, before our app starts making use of Facebook SDK we need to do authentication. The user must login with his/her account before our app starts getting benefit from
This can be done in two ways,
a) Via Native Android App
If the user is having Facebook app installed in their phones then they will be asked to login via the account they have logged in with in their facebook app.
b) Via Web View
If user is not having facebook app, then facebook login page is opened in a web browser and user can login to their account.
So by any of these two options, once the user logs in then your app gets authenticated to use their account in your app.
How to do this
Once you include Facebook SDK & Library project in your own Android app then you can simply put their built in widget in any of Your xml file and you will see the Login button there. It's code is simple,
<com.facebook.widget.LoginButton
android:id="#+id/authButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
/>
Just include the above mentioned code in your XML file (where ever you want to show Facebook Login button.) It will automatically create the Login button like the following,
Confusions/Doubts/Questions we have in our minds up till this stage
Q. How can I create the button like this in my own app? From where am I going to get logo or what color does it have etc. etc.
Ans. We don't need to create it on our own, we just put that widget in our code and the button is created automatically.
Authorization
Okay, fine we have included the Facebook login button, now user can do login into our app, next what?
Next Facebook provides many kind of options we can do, like Share something on their profile, Post a status or custom story, get user's liked pages, access their messages, posts, feeds, friend list blah blah blah.
But it is not like that user logged in with their account and we can do anything we want in our app with their facebook account.
The next term which comes in to action is Permissions
To perform a specific task we need related permission, if the user will give you permission to do so with their Facebook account, only then our app will be able to do.
For example, to access user's likes we need user_likes permission, to post something on behalf of user on their profile we need publish_actions permission etc. Complete list of permissions can be found here
So after authentication, the next thing is authorization. What our app is authorized to do with user's account.
How to get permissions
As we have already created a Login button for facebook using their button widget, now we can provide the permissions as a list to that button, so it will let the user know about what permissions you want from them when they login with their account.
Clearing the doubt here
YES, the user will be told what permissions your app wants from them while doing login. Simply you can say, the user will be told what your app can do with their facebook account like accessing their friend list, post something on their profile, reading contacts etc. However the user may or may not read it, but the login button let them know about everything.
How to add permissions to Facebook login button
LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton);
authButton.setFragment(this);
authButton.setReadPermissions(Arrays.asList("user_likes", "user_status", "publish_actions"));
So you can see we are providing a list of permissions we want. However it is even possible to ask for more permissions later on, so it is more advisable to firstly ask for basic permissions and ask for permissions like publish_actions, when user would want it.
Session
Session is a very common term mostly in case of web applications. It serves the similar purpose here. Once the user logs in with their facebook account, a Session is created in your app with the facebook and it remains until the user logs out.
Q. How to show Facebook log out button?
Ans. You will be very happy to hear this, you don't need to do anything to show log out button, once the user logs in, the login button is automatically changed to logout button.
Benefit of Session
Session object has the authentication token that enables us to perform any action with Facebook SDK.
We can get the facebook session object at any time by calling the following method,
Session session = Session.getActiveSession();
UiLifecycleHelper class
Although we have done all the steps, but we need to maintain the session properly then we are going to need this class. We just need to put it in all our activity life cycle methods
so that the facebook session is maintained accordingly.
Define an instance variable in your activity,
private UiLifecycleHelper uiHelper;
Then add the following code,
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(getActivity(), callback);
uiHelper.onCreate(savedInstanceState);
}
#Override
public void onResume() {
super.onResume();
uiHelper.onResume();
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
#Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
#Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
Now the facebook session will be maintained automatically without your headache.
Calling the Graph API
I am going to give you a very simple and basic example here, suppose we want to get the list of the pages the user has liked, then we can do it with the following code,
Session session = Session.getActiveSession();
new Request(
session,
"/me/likes",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
//Do what you want to with the response
}
}
).executeAsync();
Q. How it is going to fetch data related to the current user? We have not mentioned any user id any where?
Ans. The answer to this question is that we are using me object here, which will automatically point to the current user who has logged in to using facebook account.

Categories

Resources