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.
Related
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
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;
}
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();
}
I'd like to know the simplest way to update a user's facebook status. I'd like to simply display a 'Share' button. When the user touches 'Share':
If they are already logged in to Facebook, a dialog will appear giving them the option to edit their posting before submitting to Facebook.
If they aren't already logged in to Facebook, the will be prompted to login and then automatically shown the sharing dialog upon successful login.
Is there a simple way to do this, or do I need to implement a separate facebook login flow?
So I think I've got a pretty clean way to do it. I welcome any comments.
I'm posting my entire Facebook Manager class which does the work to login and also to bring up the feed dialog:
public class ManagerFacebook
{
private Activity mActivity;
public void updateStatus(final String name, final String caption, final String description, final String link, final String urlPicture,
final Activity activity, final ListenerShareFacebook listenerShareFacebook)
{
mActivity = activity;
// start Facebook Login
Session.openActiveSession(activity, true, new Session.StatusCallback()
{
// callback when session changes state
public void call(final Session session, SessionState state, Exception exception)
{
if (session.isOpened())
{
publishFeedDialog(name, caption, description, link, urlPicture, listenerShareFacebook);
}
}
});
}
private void publishFeedDialog(String name, String caption, String description, String link, String urlPicture,
final ListenerShareFacebook listenerShareFacebook)
{
Bundle params = new Bundle();
params.putString("name", name);
params.putString("caption", caption);
params.putString("description", description);
params.putString("link", link);
params.putString("picture", urlPicture);
Session session = Session.getActiveSession();
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(mActivity, session, params)).setOnCompleteListener(new OnCompleteListener()
{
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)
{
listenerShareFacebook.onShareFacebookSuccess();
}
else
{
// User clicked the Cancel button
listenerShareFacebook.onShareFacebookFailure("Publish cancelled");
}
}
else if (error instanceof FacebookOperationCanceledException)
{
// User clicked the "x" button
listenerShareFacebook.onShareFacebookFailure("Publish cancelled");
}
else
{
// Generic, ex: network error
listenerShareFacebook.onShareFacebookFailure("Error posting story");
}
}
}).build();
feedDialog.show();
}
}
Also, referenced above is my Listener interface so I can notify my Activity of Facebook related stuff:
public interface ListenerShareFacebook
{
void onShareFacebookSuccess();
void onShareFacebookFailure(String error);
}
I would really recommend this:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "text");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Title");
startActivity(Intent.createChooser(sharingIntent, "Share using"));
This doesn't use facebook sdk but it does use facebook app. In my view most of the people that have smartphones and facebook use this app, and expect to share everything through this app.
Also users might click to share on something else (twitter, sms, g+, email,...)
For me the best supstitute to any facebook sdk.
(you can also attach pictures)
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.