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
Related
I want to know how to send app request to all my facebook friends from android app. I tried in graph API. But, couldn't get it done.
https://graph.facebook.com/apprequests?ids=friend1,friend2&message='Hi'&method=post&access_token=ACCESS_TOKEN
I know this is a Duplicate question. But, couldn't find an answer yet.
I'm getting this error on the above API.
"All users in param ids must have accepted TOS."
I hope there will be a way to send app request to all friends from mobile on a click. Please share it.
The error message you receive ("All users in param ids must have accepted TOS") is because you are trying to send an app generated request to a user who is not connected to your app.
See the developer docs here.
Requests sent with the request dialog and app generated requests are different and you can't use app generated requests to invite users to your app.
Sending Facebook app requests are not available via the graph api. You can use the app requests java-script dialog to send the request though, you would just need to specify the user's id in the "to" property as detailed in the documentation.
Sample function:
<script>
FB.init({ appId: '**appId**', status: true, cookie: true, xfbml : true });
function sendRequest(to) {
FB.ui({method: 'apprequests', to: to, message: 'You should learn more about this awesome site.', data: 'tracking information for the user'});
return false;
}
</script>
Then just wire an onclick for each image to something like onclick="return sendRequest('**friendId**');"
Also you can call this function in javascript: It will give you all friends with photos. Also group of friends who are currently using same app. You can send request to any of them.
function sendRequestViaMultiFriendSelector() {
FB.ui({
method: 'apprequests',
message: "You should learn more about this awesome site."
});
}
See Facebook Friend Request - Error - 'All users in param ids must have accepted TOS'
Have you seen demo of "Hackbook" in the developer.facebook.com ?
You can refer HACKBOOK APP REQUEST FROM HERE.
You can achieve to post the app request to only one friend by below code.
Code:
Bundle params = new Bundle();
JSONObject attachment = new JSONObject();
JSONObject properties = new JSONObject();
JSONObject prop1 = new JSONObject();
JSONObject prop2 = new JSONObject();
JSONObject media = new JSONObject();
JSONStringer actions = null;
try {
attachment.put("name", "YOUR_APP");
attachment.put("href", "http://www.google.com/");
attachment.put("description", "ANY_TEXT");
media.put("type", "image");
media.put("src", "IMAGE_LINK");
media.put("href", "http://www.google.com/");
attachment.put("media", new JSONArray().put(media));
prop1.put("text", "www.google.com");
prop1.put("href", "http://www.google.com");
properties.put("Visit our website to download the app", prop1);
/* prop2.put("href", "http://www.google.com");
properties.put("iTunes Link ", prop2);*/
attachment.put("properties", properties);
Log.d("FACEBOOK", attachment.toString());
actions = new JSONStringer().object()
.key("name").value("APP_NAME")
.key("link").value("http://www.google.com/").endObject();
} catch (JSONException e) {
e.printStackTrace();
}
System.out.println("ACTIONS STRING: "+actions.toString());
System.out.println("ATTACHMENT STRING: "+attachment.toString());
params.putString("actions", actions.toString());
params.putString("attachment", attachment.toString()); // Original
params.putString("to", "YOUR_FRIEND_FACEBOOK_ID");
Utility.mFacebook.dialog(getParent(), "stream.publish", params,new PostDialogListener());
public class PostDialogListener extends BaseDialogListener {
#Override
public void onComplete(Bundle values) {
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(getApplicationContext(), ""+getResources().getString(R.string.facebook_response_msg_posted), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), ""+getResources().getString(R.string.facebook_response_msg_not_posted), Toast.LENGTH_SHORT).show();
}
}
}
Above code works perfect if you want to post the Apprequest only on One friend's wall. If you want to post on all then you have to make asynckTask which runs for all the friends post and post App request on all walls.
Update
Here is the link in PHP that have done same work to send request to all Facebook friends.
And [here it is clearly explained3 that it is blocked by Facebook to send a Friend Request to more then 15-20 friends.
Now, you have to only one option to do it is, use above code in AsyncTask to send Friend Request to all Friends One-by-One.
I want to post score points using facebook graph api, from my android application
I create android app in facebook developers page. I set to Native Android App , and I set Mobile Web settings like on image below
In android code I user this permissions for my app:
String[] permissions = {"publish_stream","publish_actions","user_games_activity","friends_games_activity"};
After successful login on facebook, I try to post score points to facebook using this android code
Bundle params = new Bundle();
params.putString("score", "100");
//params.putString("access_token", "token as constant");
String response = "null";
Utility.mFacebook.setAccessToken("token as constant");
try {
response = Utility.mFacebook.request("user_id/scores", params, "POST");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
And I receive this response:
{"error":{"message":"(#15) This method must be called with an app access_token.","type":"OAuthException","code":15}}
I get same error if I use Graph API Explorer:
In facebook settings ->Apps -> AppName -> Advanced->App Type is set to "Web" (I also try with Native/Desktop but I get same error)
Can anyone help me and tell me how to sent score from my android app to fb?
Thanks
"(#15) This method must be called with an app access_token."
Looks like you tried with an user access token.
See https://developers.facebook.com/docs/authentication/applications/ on how to get an app access token.
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.
Can anybody suggest a good method for creating a facebook share implementation for my application.
I have created the test account and API key for the facebook developer site...
I need to implement in such a way that,when the fbshare button is clicked,a particular content(dynamic content) should be posted as a status link in the corresponding linked facebook account...
Apart from the fb developers,i need some other way of implementing it...
Suggestions expected...(possibly better results expected)
Hi use this method in your code in facebook handler class
public void postToFBWall(final String message, final String image){
Thread thread = new Thread(){
public void run(){
try{
String descripton = "This is the plain text copy next to the image. All work and no play makes Jack a dull boy.";
Bundle parameters = new Bundle();
parameters.putString("message", message);// message to be posted on facebook wall
parameters.putString("link", image);//link of image to be posted on facebook wall
parameters.putString("name", "My wish");// name of link
parameters.putString("description", descripton);// description of you post
String response1 = facebook.request("me/feed", parameters, "POST");
Log.v("facebook response", response1);
}catch (Exception e) {
}
}
};thread.start();
}
Try this one
https://developers.facebook.com/docs/mobile/android/hackbook/
it may helps you.
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.