Android Facebook API - sending an app invite to a friend - android

I managed to login to Facebook / get permissions.. retrieve friends data, names/ids etc.
The issue is that I cannot send an app invite to my friends. I'd like to send the invite without a dialog to a single person. But it seems that's wishful thinking. Now I'd settle for anything. It seems nothing will do the job!
I tried the dialog provided by Facebook Graph API but it tells me that the display is not supported (error 103). Also tried the fix modifying the url inside the Facebook SDK to not point to the mobile version and set the display as popup. Still no good (same error);
Any thoughts on this?
Thank you in advance.
(BTW, it seems to me like Facebook is a very unreliable service!)

This code will bring up an app invite dialog (and I don't know how to send an invite without a dialog). Note: assumes that facebook has been successfully authorized/logged in:
Facebook facebook = new Facebook( MY_APP_ID );
...
Bundle parameters = new Bundle();
parameters.putString( "message", "Check this out!" );
facebook.dialog( activity, "apprequests", parameters,
new Facebook.DialogListener()
{
public void onComplete() { ... }
public void onFacebookError( FacebookError e ) { ... }
public void onError(DialogError e) { ... }
public void onCancel() { ... }
} );

Related

Android Linkedin SDK DeepLink automatically crash

I am trying to "Deeplink" to some user profile on my Android application
but the app always reacts the same way. It opens the offical Linkedin Application, which crashes immediatly, and then it doesn't enter in the callback (onDeepLinkError)...
I tried both openCurrentProfile and openOtherProfile methods...
My session is valid, and I am authenticated, everything's good on that side.
Here is my piece of code :
DeepLinkHelper deepLinkHelper = new DeepLinkHelper();
deepLinkHelper.openCurrentProfile(getActivity(), new DeepLinkListener() {
#Override
public void onDeepLinkSuccess() {
}
#Override
public void onDeepLinkError(LIDeepLinkError error) {
Log.e("ERROR", error.toString());
}
});
EDIT : It seems to crash only on my smartphone, I ran the app on a friend device, and I works properly... Any ideas would be extremely apprieciated :D

Facebook android sdk invitation request dialog does not select the contacts to invite

I am using FACEBOOK SDK and SIMPLE FACEBOOK to give a login in my app. When i use facebook sdk's invite api to invite my friends to join my app, it shows me a web dialog so that i can select friends to invite. But as soon as i select any of the friends, it gets selected momentarily and automatically gets deselected('plus sign' changes to 'tick mark' for a moment and changes back to 'plus' gain automatically) not allowing me to select my friends and send request. This is the piece of code i am using to show 'invite request dialog'
OnInviteListener onInviteListener = new OnInviteListener() {
#Override
public void onFail(String reason) {
mResult.setText(reason);
}
#Override
public void onException(Throwable throwable) {
mResult.setText(throwable.getMessage());
}
#Override
public void onComplete(List<String> invitedFriends, String requestId) {
String print = "<u><b>Requet Id</b></u><br>" + requestId + "<br><br>";
print += String.format("<u><b>Invited Ids (%d)</b></u><br>", invitedFriends.size());
print += Utils.join(invitedFriends.iterator(), "<br>");
mResult.setText(Html.fromHtml(print));
}
#Override
public void onCancel() {
mResult.setText(Html.fromHtml("<u><b>Result</b></u> <br>Canceled invitation"));
}
};
SimpleFacebook.getInstance(getActivity()).invite(INVITE_MESSAGE, onInviteListener, null);
KEY POINTS:
1) I am facing this problem with XIAOMI REDMI(4.3 android) only, NO OTHER DEVICE shows this behavior.
2) On the same devices, SIMPLE FACEBOOK SAMPLE to invite friends works completely fine.
3) The URL returned by facebook to populate the web dialog is working fine on browser.

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.

How to revoke all Facebook permissions using Android SDK?

I'm having a problem revoking Facebook permissions using the Android SDK.
There's a case in my app where I want to revoke all permissions. According to the Facebook documentation, you can use AsyncFacebookRunner to do this, and "if you don't specify a permission then this will de-authorize the application completely."
I'm currently doing it like this:
String method = "DELETE";
Bundle params = new Bundle();
params.putString("permission", "");
mAsyncRunner.request("/me/permissions", params, method, new RequestListener()
{ ... }, null);
using the request signature like this:
void request(String graphPath, Bundle parameters, final String httpMethod,
RequestListener listener, final Object state)
The onComplete() callback function seems to come back OK, but doesn't appear to have de-authorized the access token. I'm inferring this because the next time I call facebook.authorize(), it works without pushing the user to the Facebook login page.
Any ideas what I need to change to completely de-authorize an access token? Or is there a different/better way to do this? Many thanks!
For anybody looking to do this in later versions of the SDK/Graph API - It appears the correct way to do this now is as shown here https://developers.facebook.com/docs/graph-api/reference/user/permissions/
new Request(
session,
"/me/permissions/{permission-to-revoke}",
null,
HttpMethod.DELETE,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
Leaving the /{permission-to-revoke} off of the second parameter will revoke all the permissions
You can delete the entire application (not only permissions) from users Facebook account using latest SDK (mine is 4.1.1)
void deleteFacebookApplication(){
new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/permissions", null, HttpMethod.DELETE, new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse response) {
boolean isSuccess = false;
try {
isSuccess = response.getJSONObject().getBoolean("success");
} catch (JSONException e) {
e.printStackTrace();
}
if (isSuccess && response.getError()==null){
// Application deleted from Facebook account
}
}
}).executeAsync();
}
It appears from this post: Facebook deauthorize my app and others that it's not possible to deauthorize an application programmatically. Unfortunately, the call above returns successfully to onCreate() but does nothing to deauth/delete the app for the user.
Bottom line: It looks like the only way to deauth an app is for the user to do it directly in Facebook. If anyone knows differently, please say so - but otherwise, don't waste your time trying! Thanks.
I am using the code suggested in the question and it completely de-authorized my test application. Tested it several times and it worked every each one of them.
This is also the code suggested in the official facebook documentation here: https://developers.facebook.com/docs/mobile/android/build/ - Step 7

FACEBOOK/TWITTER login no longer work on Android app after updating Facebook APK (login disappears immediately!)

I have an App that allows users to log in with their twitter, facebook, and gmail so I can send them updates to each. I just downloaded the newest facebook APK and now I every time I click on the twitter or facebook logins, the login only shows up for a split-second and then disappears. Here's what I've changed:
public static Facebook load(Context context) {
Facebook fb = new Facebook(context.getString(R.string.facebook_App_ID));
restore(fb, context);
return fb;
}
--It didn't used to take the APP_ID as a parameter but the new APK enforces you to do it here I believe.
facebook.authorize(this, PERMISSIONS,new LoginDialogListener());
-- This previously took the APP_ID as a parameter but now it is passed in when the facebook object is created.
--NOTE: I already tried using FORCE_DIALOG_AUTH and that did not work.
private final class LoginDialogListener implements DialogListener
{
public void onComplete(Bundle values) {
System.out.println("fb success");
FacebookHelper.save(facebook, SMTPSettings.this);
updateFacebookSumamry();
}
public void onFacebookError(FacebookError error) {
L.p("loginDialogListener",4900374);
System.out.println("fb error " + error.getMessage());
}
public void onError(DialogError error) {
L.p("loginDialogListener",4900387);
System.out.println("fb error " + error.getMessage());
}
public void onCancel() {
L.p("loginDialogListener",4900392);
System.out.println("fb cancel");
}
}
-I haven't changed anything with my dialogListener. But every time the control moves to the Dialoglistener it just goes straight into the onError function.
Twitter login no longer works but gmail still does. I don't know exactly what i changed that makes twitter no longer work too, but any help or tips would be greatly appreciated!
Thanks!
For anyone that has seen this, I thought I might post what I remember solved the problem. I uninstalled the other facebook apps I had on my phone like Andreas said above. That didn't solve it immediately, but restarting the phone made it work perfectly. I think it had to do with clearing out temporary memory files or something...not a very complicated problem, but all else fails, give it a clean restart!

Categories

Resources