In my application user can share information with different apps using:
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Link from my APP");
shareIntent.putExtra(Intent.EXTRA_TEXT, "http://aaa.com/");
startActivity(Intent.createChooser(shareIntent,"Share via:"));
It works fine./gmail,sms,google+..../
The only problematic app is Facebook. It starts dialog, but there is no info in fields.
Tried different TAGs, bout nothing :(
The only result is: If I put URL as EXTRA_TEXT - it not shown as text, but Facebook dialog read tags from URL and place them on dialog frame.
Any ideas to fill data in dialog.
Already have code to share wia sdk with or without dialog but this is not good for some reasons.
You need to integrate facebook sdk
Go through the following link it shows how to integrate facebook sdk
[http://developers.facebook.com/docs/mobile/android/sso/][1]
and u need to put some code in your java file as follows
try {
String response = facebook.request("me");
Bundle parameters = new Bundle();
parameters.putString("message", " your link");
parameters.putString("description", "");
response = facebook.request("me/feed", parameters,
"POST");
Log.d("Tests", "got response: " + response);
if (response == null || response.equals("") ||
response.equals("false")) {
Log.v("Error", "Blank response");
}
} catch(Exception e) {
e.printStackTrace();
}
All problems disappear after putting correct Android Key Hash.
Now share works correct.
Related
I'm trying to create an android application which would allow the users to post messages on their facebook wall and also on their friends wall.
I've been through a few tutorials but in each of them is done barely the same thing:integrate facebook in application, the login authorization and posting a predifined message on the walll.
I'm using facebook sdk and I wonder is possible for the user to write directly to his wall in a dialog window???
What kind of authorization I need and if u could give me an example would be great.Thank u!
Take a look at this tutorial here and there is part 2 here. It will guide you though setting up the application to use facebook. Once you have all that setup you can use a function like this to post a msg to someones wall:
/**
* Post to a friends wall
* #param msg Message to post
* #param userId Id for friend to post to or null to post to users wall
*/
public void postToWall(String msg, String userID) {
try {
if (isSession()) {
String response = mFacebook.request((userID == null) ? "me" : userID);
Bundle parameters = new Bundle();
parameters.putString("message", msg);
response = mFacebook.request(((userID == null) ? "me" : userID) + "/feed", parameters, "POST");
Log.d(TAG,response);
if (response == null || response.equals("") ||
response.equals("false")) {
Log.v("Error", "Blank response");
}
} else {
// no logged in, so relogin
Log.d(TAG, "sessionNOTValid, relogin");
mFacebook.authorize(this, PERMS, new LoginDialogListener());
}
} catch(Exception e) {
e.printStackTrace();
}
}
I had used a facebook app to post message on wall from https://github.com/facebook/facebook-android-sdk.
Here after user allows the app to use his/her profile, dialog feed comes with an editable area to publish or skip. I want a predefined message there but user will not be able to modify it. I am able to send the predifined message but its editable. How to make it uneditable.
Does any one knows how to do it??
You can just use a function to post directly to the users wall. Just make sure that it is clear to the user that the button posts directly, perhaps use a dialog to get them to confirm they want to post. Here is the code I use:
/**
* Post to a friends wall
* #param msg Message to post
* #param userId Id for friend to post to or null to post to users wall
*/
public void postToWall(String msg, String userID) {
Log.d("Tests", "Testing graph API wall post");
try {
if (isSession()) {
String response = mFacebook.request((userID == null) ? "me" : userID);
Bundle parameters = new Bundle();
parameters.putString("message", msg);
response = mFacebook.request(((userID == null) ? "me" : userID) + "/feed", parameters, "POST");
Log.d(TAG,response);
if (response == null || response.equals("") ||
response.equals("false")) {
Log.v("Error", "Blank response");
}
} else {
// no logged in, so relogin
Log.d(TAG, "sessionNOTValid, relogin");
mFacebook.authorize(this, PERMS, new LoginDialogListener());
}
} catch(Exception e) {
e.printStackTrace();
}
}
The dialog contains a WebView that loads the actual content from a Facebook URL. So to modify the editable area, you would need to modify the DOM of this webpage. See this question for more information about doing that. It is unclear to me from the answers in that question if this is possible. If it is, you'll need to add the code to the FbDialog class in the Facebook Android SDK.
I am posting some data on facebook from an android app.
It works fine, apart from the fact that the dialog window is not showing the parameters, like text, etc... ![Please see image attached][1]
This is the code that I am using to show the dialog...
try
{
Bundle parameters = new Bundle();
parameters.putString("message", "this is a test");// the message to post to the wall
facebookClient.authorize(activity.this, listener);
facebookClient.dialog(myContext, "stream.publish", parameters, listener);// "stream.publish" is an API call
}
catch (Exception e)
{
// TODO: handle exception
Log.i("test","error = "+e.toString());
}
does anybody knows what I am doing wrong?
Thanks a lot
I have build an android application in which I've integrated faceboook using the facebook-sdk package.I've also succeded to retrieve in my application the name of all my facebook friends, their names and their id's.Further I want to send from my application an invitation to all facebook friends to join a website.Can u point me in the right direction cause I haven't found anything on the internet.Thank you
Try using the code below, if you follow the tutorials i gave you in your other question it will work no probs!
protected void postOfferToWall(String userID){
try {
if (isSession()) {
String response = mFacebook.request((userID == null) ? "me" : userID);
Bundle params = new Bundle();
params.putString("message", "message goes here");
params.putString("link", "http://mysite.com");
params.putString("caption", "Click the link");
params.putString("description", "description of link");
params.putString("name", "name of link");
params.putString("picture", "http://url.to.my.picture/pic.jpg");
response = mFacebook.request(((userID == null) ? "me" : userID) + "/feed", params, "POST");
Log.d("Tests",response);
if (response == null || response.equals("") ||
response.equals("false")) {
Log.v("Error", "Blank response");
}
} else {
// no logged in, so relogin
Log.d(TAG, "sessionNOTValid, relogin");
mFacebook.authorize(this, PERMS, new LoginDialogListener());
}
}catch(Exception e){
e.printStackTrace();
}
}
For a quick reference using the Graph API to post to your friends wall, see Graph API - Facebook Developers. There is a subsection called Publishing, where they use curl to post to a friends wall. Of course you need to get the access tokens and permissions to do such activities but it is all explained here.
I'm new to Facebook API on Android, and basically, what I'm trying to do is creating custom wall post for an application I'm developing.
Like when you listen a Shazam a song and you can share the result with your friends.
I believe I've got to create a custom attachment. Here's my code for setting the attachment:
mPostButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Bundle myParams = new Bundle();
String attachment="{\"name\":\"Gran Turismo 5\"," +
"\"href\":\"http://www.unknown.com/?lang=fr\"," +
"\"caption\":\"Sony Computer Entertainment\",\"description\":" +
"\"Une vidéo proposée par Cedemo.\",\"media\":" +
"[{\"type\":\"image\",\"src\":" +
"\"http://www.unknown.com/prepicture//thumb_title/15/15061_1.jpg\"," +
"\"href\":\"http://www.unknown.com/?lang=fr\"}],\"properties\":" +
"{\"Autre lien\":{\"text\":\"Cedemo\",\"href\":\"http://www.unknown.com\"}}}";
myParams.putString("attachment", URLEncoder.encode(attachment);
mFacebook.dialog(Option.this, "stream.publish",myParams,
new SampleDialogListener());
And then, later on:
public class SampleDialogListener extends BaseDialogListener {
public void onComplete(Bundle values) {
final String postId = values.getString("post_id");
if (postId != null) {
Log.d("Facebook-Example", "Dialog Success! post_id=" + postId);
mAsyncRunner.request(postId,values, new WallPostRequestListener());
} else {
Log.d("Facebook-Example", "No wall post made");
}
}
}
I didn't wrote the attachment String, It's just a test taken from another question made in this forum. Anyway, when I call myAsync.request, my app shows an error message, how am I supposed to pass the attachment to my dialog?
Hope I've been clear enough.
Are you sure you need to set custom parameters? It sounds like you can just want to post a Facebook message directly to the wall: you can do this by simply handing in the message parameter as a string -- you only need all that JSON if you want to attach an image etc. And note on facebook's page it says using this api call won't post a status update that others can see on their feed, it will just appear on their own wall. If you just want to post a message with a link you should just be able to use your mAsyncRunner (once you have your valid Facebook session) using this:
String message = "Post this to my wall";
Bundle parameters = new Bundle();
parameters.putString("message", message);
mAsyncRunner.request("me/feed", parameters, "POST", new WallPostRequestListener());
Also may help if you posted the error/response code you're getting from Facebook.