Facebook Feed Dialog showing error - android

I have integrated facebook sdk with my native android app.
Currently i am trying to open facebook feed dialog from base adapter class and it is showing me error.
I have taken reference from the below link.
https://developers.facebook.com/docs/android/feed-dialog
https://developers.facebook.com/docs/reference/dialogs/feed/
Everytime it shows me different errors .
I don't know what's wrong with my code.
I am also putting my code here.
private void publishFeedDialog() {
Bundle params = new Bundle();
params.putString("name", "Facebook SDK for Android");
params.putString("caption", "Build great social apps and get more installs.");
params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
params.putString("link", "https://developers.facebook.com/android");
params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
WebDialog feedDialog = (
new WebDialog.FeedDialogBuilder(CONTEXT,
Session.getActiveSession(),
params))
.setOnCompleteListener(new WebDialog.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) {
Toast.makeText(CONTEXT,
"Posted story, id: " + postId,
Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(CONTEXT,
"Publish cancelled",
Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(getActivity().getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(CONTEXT,
"Error posting story",
Toast.LENGTH_SHORT).show();
}
}
})
.build();
feedDialog.show();
}

Try this, Go to the Facebook App. Edit its settings. On the Advanced settings page, disable the "Stream post URL security" option.
How to go.
Go to developers.facebook.com/apps On the left hand side, click your app to select it.
Next to the "Settings" section in the middle column, there's an "Edit Settings" link.
Click that. On the new page, under the "Settings" menu on the left hand side, click "Advanced".
Under the "Migrations" section, find "Stream post URL security". Set it to "Disabled". Click the "Save Changes" button at the bottom of the screen..
It will look something like this
You can see by default this is on just click it OFF and click on Save Changes and then try to clean your project and run it again. Might be this will help you.

Related

Facebook Share Dialog is not opening

As per this link here, I have installed the SDK 3.2.1 and implemented a uiHelper, along with FacebookDialog like this:
if (FacebookDialog.canPresentShareDialog(getApplicationContext(),
FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
// Publish the post using the Share Dialog
Toast.makeText(this, "if", Toast.LENGTH_LONG).show();
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(
this).setLink("https://developers.facebook.com/android")
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
} else {
Toast.makeText(this, "else", Toast.LENGTH_LONG).show();
// Fallback. For example, publish the post using the Feed Dialog
publishFeedDialog();
}
For publishFeedDialog() I have:
private void publishFeedDialog() {
Bundle params = new Bundle();
params.putString("name", "Facebook SDK for Android");
params.putString("caption",
"Build great social apps and get more installs.");
params.putString(
"description",
"The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
params.putString("link", "https://developers.facebook.com/android");
params.putString("picture",
"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(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) {
Toast.makeText(getApplicationContext(),
"Posted story, id: " + postId,
Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(getApplicationContext(),
"Publish cancelled", Toast.LENGTH_SHORT)
.show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(getApplicationContext(),
"Publish cancelled", Toast.LENGTH_SHORT)
.show();
} else {
// Generic, ex: network error
Toast.makeText(getApplicationContext(),
"Error posting story", Toast.LENGTH_SHORT)
.show();
}
}
}).build();
feedDialog.show();
}
Now the FacebookDialog.canPresentShareDialog is always going to false even when Fb app is installed in the phone and then the publishFeedDialog() is called. But the app crashes after this.
What is the solution for this? Why is the normal facebook dialog shown when the app is there in my phone? (I am using Lenevo model, if that helps)
You need a newer FB app in order for the share dialog to work. Make sure you download the latest ones!
Also, no, you don't need login to enable the share dialog.

facebook request dialog android shows only a partial list of friends

Im trying to use facebook request dialog to enable the user to pick a friend to challenge in a turn based trivia android game.
i dont have a web version of the game so i dont canvas.
ive set up a request dialog that shows the list friends which works fine when i log in with facebook test users but when i login with my user who is also administrator of the facebook app then the dialog shows a list of only 5 friends. the dialog allows to search for more friends and when i do that i can search for other friends which do not appear in the list.
my user has "public_profile","read_friendlists", "user_friends" permissions.
the request dialog code
private void sendRequestDialog() {
Bundle params = new Bundle();
params.putString("message", "Learn how to make your Android apps social");
params.putString("filters", "app_non_users");
WebDialog requestsDialog = (
new WebDialog.RequestsDialogBuilder(MainActivity.this,
//getActivity(),
Session.getActiveSession(),
params))
.setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values,
FacebookException error) {
if (error != null) {
if (error instanceof FacebookOperationCanceledException) {
Toast.makeText(getApplicationContext(),
//getActivity().getApplicationContext(),
"Request cancelled",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(),
//getActivity().getApplicationContext(),
"Network Error",
Toast.LENGTH_SHORT).show();
}
} else {
final String requestId = values.getString("request");
if (requestId != null) {
Toast.makeText(getApplicationContext(),
//getActivity().getApplicationContext(),
"Request sent",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(),
//getActivity().getApplicationContext(),
"Request cancelled",
Toast.LENGTH_SHORT).show();
}
}
}
})
.build();
requestsDialog.show();
}
i dont understand why its not showing the entire friends list. please help.
in addition, is this method of challenging a friend for a game is permitted by facebook is there another more recommended method?
Thanks!
user_friends will return only the friends who used the app that makes the request. via Graph API Reference

Sharing on facebook without the native app installed

I'm trying to share some stuff on Facebook. following this guide I managed to complete the sharing when you have the native app. However, when I reached this:
Step 4: Using the Feed Dialog as fallback. It says that to be able to use a fallback method, I need to add the code below
private void publishFeedDialog() {
Bundle params = new Bundle();
params.putString("name", "Facebook SDK for Android");
params.putString("caption", "Build great social apps and get more installs.");
params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
params.putString("link", "https://developers.facebook.com/android");
params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
WebDialog feedDialog = (
new WebDialog.FeedDialogBuilder(getActivity(),
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) {
Toast.makeText(getActivity(),
"Posted story, id: "+postId,
Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(getActivity().getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(getActivity().getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(getActivity().getApplicationContext(),
"Error posting story",
Toast.LENGTH_SHORT).show();
}
}
})
.build();
feedDialog.show();
}
After adding this, I get errors at getActivity(), I fix this by using MyClass.this.
Then, when I run the app (I directly run this method at startup) my application crashes and I get some error like "attempted to use session that was not open"
Anyone know how to be able to share stuff without the native app installed?
The error is caused because the user has not logged in to Facebook via your app. You will need to implement the Login with Facebook somewhere in your app. Even if the user does not have the native app installed, the Facebook SDK will fall back on the webdialog to request the user to log in. Thus, You will need to check if the session is opened (i.e. user has logged in).
Session session = Session.getActiveSession();
boolean isSessionOpen = (session != null && session.isOpened());
if(!isSessionOpen) {
Toast.makeText(getApplicationContext(),"Please Login With Facebook First!", Toast.LENGTH_SHORT).show();
return;
}

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 share message on facebook wall from my Android app?

I think, this is very simple problem. I have one button in my app. If i click it it executes one method. In this method i want to share "Hi this is xxx using xxxxx product" message on user's facebook wall. How can i do that? Is there any tutorials?
myMethod(){
//share on fb wall
}
From Sharing in Android tutorial:
Prerequisites
Before you can share to Facebook from your app, or attempt to follow
any of the sharing tutorials, you will need:
Your environment set up A Facebook app properly configured and linked
to your Android app, with SSO enabled The Facebook SDK added to your
project If you haven't done this and need help doing so, you can
follow our getting started guide.
Then essentially, have your myMethod call this:
private void publishFeedDialog() {
Bundle params = new Bundle();
params.putString("name", "Facebook SDK for Android");
params.putString("caption", "Build great social apps and get more installs.");
params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
params.putString("link", "https://developers.facebook.com/android");
params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
WebDialog feedDialog = (
new WebDialog.FeedDialogBuilder(getActivity(),
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) {
Toast.makeText(getActivity(),
"Posted story, id: "+postId,
Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(getActivity().getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(getActivity().getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(getActivity().getApplicationContext(),
"Error posting story",
Toast.LENGTH_SHORT).show();
}
}
})
.build();
feedDialog.show();
}

Categories

Resources