How to send friend request using Facebook dialogs on Android? - android

I want tot send a friend request using the Facebook Android SDK. I'm currently using this code (which I got from here):
Bundle parameters = new Bundle();
parameters.putString("APP_ID","USERNAME");
facebook.dialog(this, "friends", parameters, this);
where APP_ID is the Facebook ID of my app and USERNAME is the username of the friend I want to add. This leads to the following error:
API Error Code:100
Invalid parameter
The parameter id is required
I thought the id parameter meant the APP_ID.
I have gone through the relevant documentation regarding dialogs at http://developers.facebook.com/docs/reference/dialogs/friends/ and http://developers.facebook.com/docs/reference/androidsdk/dialog/, but still can't figure it out.
Any help is appreciated.

Should be something like:
Bundle parameters = new Bundle();
parameters.putString("id", USER_ID);
facebook.dialog(this, "friends", parameters, this);
In case that this is an activity which also implements DialogListener.
As it says in the documentation:
app_id - Your application's identifier. Required, but automatically
specified by most SDKs.
id - Required. The ID or username of the
target user to add as a friend.

You can use:
WebDialog.RequestsDialogBuilder requestBuilder = (new WebDialog.RequestsDialogBuilder(this,
Session.getActiveSession(), params)).setOnCompleteListener(
new OnCompleteListener() {
#Override
public void onComplete(Bundle values,
FacebookException error) {
if (error != null) {
} else {
final String requestId = values
.getString("request");
if (requestId != null) {
//if the user completed the action,
} else {
}
}
}
});
WebDialog requests = requestBuilder.build();
requests.show();
If you want to set the request to preselected friends just add the following to the requestBuilder:
requestBuilder.setTo("FRIEND_ID, ANOTHER_FRIEND_ID"), before building the dialog.
What is strange is that it accepts the list of friends as a concatenated list of ids, not an Array nor list. I didn't find in in the docs, but just found that it works

Related

'Base forbidden. Need user.' error when trying to create a QBCustomObject

When I try to save QBCustomObject, response from server sometimes it says
Base forbidden. Need User.
Before saving, I checked QBChatService.getInstance().isLoggedIn() and it returns true.
This error happens for both:
just after logging in
and, for example, 10 minutes afterwards
Disappears after re-launching the app and signing in process.
HashMap<String, Object> fields = new HashMap<String, Object>();
fields.put("name", name);
fields.put("User ID", currentUser.getId());
QBCustomObject qbCustomObject = new QBCustomObject();
qbCustomObject.setUserId(currentUser.getId());
qbCustomObject.setClassName("Group");
qbCustomObject.setFields(fields);
QBCustomObjects.createObject(qbCustomObject, new QBCallbackImpl() {...});
Here are the chain of actions which leads to creating QBCustomObject:
QBAuth.createSession() -> QBUsers.signIn() -> QBChatService.getInstance().loginWithUser()
Why does this error happen?
Seems like I've found the bug. I didn't used the QBUser object I got from .signIn() response. Here is what I mean:
QBUsers.signIn(user, new QBCallbackImpl() {
#Override
public void onComplete(Result result) {
if (result.isSuccess()) {
QBUser signedInUser = (((QBUserResult) result).getUser());
signedInUser.setPassword(password);
//...
loginToChat(signedInUser);
//...
}
});
Chat login and login to Application - they are different logins.
In order to create any object in QuickBlox (except a chat message) - you must act on the user's behalf
More info here how to create a record http://quickblox.com/developers/SimpleSample-customObjects-android#Create_record_using_Android_SDK
There you will find a link how to login a user to application http://quickblox.com/developers/SimpleSample-users-android#Sign_In_.26_Social_authorization
create your session with QBUser.
ex :- QBAuth.createSession(new QBUser("user_name", ""))

Send Facebook request from android does not show message preview and does not send to friends

In my android app, after the Facebook login and authentication, user is allowed to send the request to his friend to invite them to join the app. Moreover, I need to know who is invited, after the user sends requests.
My problems are as following:
When user wants to send request, the message preview is not
showing at the top of dialog box.
When user tap on invite button, a black screen cover dialog box. if
tap on black cover, it is disappearing.
When user selects friends and tap on send, the request is not going
to the friends.
Send request code is as following:
private void sendRequestDialog() {
Bundle params = new Bundle();
params.putString("message", "Learn how to make your Android apps social");
WebDialog requestsDialog = (new WebDialog.RequestsDialogBuilder(FBLoginActivity.this, Session.getActiveSession(), params))
.setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values, FacebookException error) {
if (error != null) {
if (error instanceof FacebookOperationCanceledException) {
Toast.makeText(FBLoginActivity.this, "Request cancelled", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(FBLoginActivity.this, "Network Error", Toast.LENGTH_SHORT).show();
}
} else {
final String requestId = values.getString("request");
if (requestId != null) {
Toast.makeText(FBLoginActivity.this, "Request sent", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(FBLoginActivity.this, "Request cancelled", Toast.LENGTH_SHORT).show();
}
}
}
}).build();
requestsDialog.show();
}
I followed the Facebook Send request implementation guide but I am not getting same result.
Note:
My application is not published on Play store yet.
App configuration on Facebook developer dashboard: Sand box disabled and it has not submitted to the Facebook for any permissions and approval.(I want to know for send request I need to do that?)
I am suspecting that I am missing some configuration on Facebook app dashboard.
I am appreciated for any help.
Finally I got the answer. The missing point for sending request to friend from your app is to provide Facebook configuration to handle request properly which is not mentioned in Facebook documentation.
In Facebook dashboard, go the setting and add App on Facebook (Add platform section), facebook allocate a page in Facebook domain like https://apps.facebook.com/Your-name-space, then you could set your Canvas URL and Canvas Secure URL to bring the URL content to the canvas.
(for more info about how to configure Canvas URL refer to [this][https://devcenter.heroku.com/articles/configuring-your-facebook-app-as-a-canvas-page]
After all when send request to friends, friends recieve notification and when click on it they will redirect to https://apps.facebook.com/Your-name-space.
Your code above doesn't have target/destination id.
before sending a request you need to:
Get the list of facebook friends (example here: Android: get facebook friends list)
Show a dialog with friends... (an activity.. fragment.. or anything else.) and let user choose friend he want to invite (You need target user identifier ID)
Send the request in the following way:
Bundle postParams = new Bundle();
postParams.putString("message", title);
postParams.putString("data", message);
postParams.putString("to", target);
WebDialog requestsDialog = (new WebDialog.RequestsDialogBuilder(getMainActivity(), Session.getActiveSession(), postParams)).setOnCompleteListener(new ApplicationRequestCallback()).build();
where ApplicationRequestCallback is a class that implements OnCompleteListener
Ahmadi , Even i faced the similar issue . Later i fixed by disabling from sandboxmode and Providing Canvas URL in facebook app registration. If this answer is helpful reply back.

Android Facebook FeedDialogBuilder post privacy/audience

I'm trying to allow a user to post there status to their FB wall from with in my Android app. I'm having a problem with the Privacy/Audience for the post is always set to "Only Me" I want to set this to "Friends", but I can't find a way to do this. Below is my code snippet of how i'm accomplishing this:
Bundle params = new Bundle();
params.putString("description", " ");
params.putString("name", "testtest app");
params.putString("link", "http://www.testtestapp.com/");
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(QuickCalc.this, Session.getActiveSession(), params)).setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values, FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
} else {
// User clicked the Cancel button
}
} else {
// Generic, ex: network error
}
}
})
.build();
feedDialog.show();
The audience level is set when the user first authorizes your app with write permissions, and cannot be changed by the app (for pretty obvious reasons).
When you ask for write permissions, you can request a certain default audience level by calling the setDefaultAudience method, but the user can edit the app settings from the Facebook website, and change the audience setting at any time.

Invite Friend Request using new Android SDK 3.0

I am using the new Facebook SDK 3.0 that just released on Android. I want to let the user invite his/her friends to the app.
However, in the new SDK you do NOT create a new Facebook object with the App ID. You extend the FacebookActivity as given in the tutorial: http://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/
Hence, I could not use the reference material provided to send invites to friends since there is no facebook object to call the dialog method on.
http://developers.facebook.com/docs/howtos/androidsdk/3.0/send-requests/
I've already setup the Friend Picker UI and can get GraphUser objects that the user selected.
http:// developers(dot)facebook(dot)com/docs/tutorials/androidsdk/3.0/scrumptious/show-friends/
But, I can't figure out how to invite the friends that the user has selected.
Does anyone know how to invite friends in the new SDK? Would you be using the FbDialog class? If so, what is the url string that needs to be provided? (I tried using "apprequests", but that didn't work)
Thanks for your help.
Try this link:
https://developers.facebook.com/docs/howtos/androidsdk/3.0/send-requests/
private void sendRequestDialog() {
Bundle params = new Bundle();
params.putString("message", "Learn how to make your Android apps social");
WebDialog requestsDialog = (
new WebDialog.RequestsDialogBuilder(getActivity(),
Session.getActiveSession(),
params))
.setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values,
FacebookException error) {
final String requestId = values.getString("request");
if (requestId != null) {
Toast.makeText(getActivity().getApplicationContext(),
"Request sent",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity().getApplicationContext(),
"Request cancelled",
Toast.LENGTH_SHORT).show();
}
}
})
.build();
requestsDialog.show();
}
You can use com.facebook.widget.WebDialog class for this:
WebDialog dialog = new WebDialog.Builder(myActivity, mySession, ...).build();
dialog.show();
Also see helper classes WebDialog.FeedDialogBuilder and WebDialog.RequestsDialogBuilder that make it easier to build these dialogs.

Get Facebook friend list - Android

I am new in Facebook integration with android. I've logged in to Facebook by using facebook-android-SDK. Now I want to get all friends details and display in ListView. How can I do this?
Please help me
Thanks in advance
Go with following code to get frends list :
Bundle params = new Bundle();
params.putString("fields", "name, picture");
JSONObject jsonFrends = Util.parseJson(facebook.request("me/friends", params));
I would recommend following the tutorial on Fetching User Data and then instead of executing
...
if (state.isOpened()) {
userInfoTextView.setVisibility(View.VISIBLE);
// Request user data and show the results
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
#Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
// Display the parsed user info
userInfoTextView.setText(buildUserInfoDisplay(user));
}
}
});
}
...
use Request.executeMyFriendsRequestAsync which is part of the Request class.
EDIT: Which also has the advantage of using the Facebook Android SDK to parse the response.
You can do by this way :
Using the graph API: https://graph.facebook.com/me/friends?access_token="your access_token"

Categories

Resources