Post message on facebook wall from android. - android

I have sucessfully login to facebook from myapp and got the accesstoken but when i post the message on my wall i got the folowing exception.
{"error":{"message":"(#10) Application does not have permission for this action","type":"OAuthException","code":10}}
Code is:
Bundle parameters = new Bundle();
parameters.putString("message", "hello ...");
parameters.putString(Facebook.TOKEN, mFacebook.getAccessToken());
try {
String response = mFacebook.request("me/feed", parameters,"POST");
} catch (IOException e)
{}

Please give publish_stream permission from your own application.
private static final String[] PERMISSIONS =
new String[] {"publish_stream", "read_stream",};
When you initialize login button at that time you need to pass the permission.
mLoginButton.init(this, mFacebook,PERMISSIONS);

Related

Android - Issue in facebook sharing using facebook sdk

I'm using the facebook sdk to share on the facebook wall. If I'm using the admin account I'm able to share on facebook. Admin account means created app account. If I'm using an other facebook account I'm not able to share.
{"error":{"message":"(#200) The user hasn't authorized the application to perform this action","type":"OAuthException","code":200}}
Below is the code snippet
private Facebook facebook = new Facebook(APP_ID);
private static final String[] PERMISSIONS = new String[] { "publish_actions" };
Bundle parameters = new Bundle();
parameters.putString("message", message);
parameters.putString("description", "topic share");
try {
facebook.request("me");
String response = facebook.request("me/feed", parameters, "POST");
Log.d(TAG, "got response: " + response);
} catch (Exception e) {
}
Can anyone help to fix this issue?
Thanks
Kamal

Get friend interests using android facebook SDK

In my app my intention is to get some interests of a friend like music, books, tv. This information is public. For this I think I don't need to send a permission.
Based on facebook (poor)documentation, mainly this links:
Field Expansion to get friend interest I only need to pass friend ID in the expanded friends field.
Doing some tests on GraphExplorer I see it creates the following query to get movies form some friend:
MY_ID?fields=friends.uid(FRIEND_ID).fields(movies)
I use this and execute execute this code on a Request.newMyFriendRequest asynchronously:
Session activeSession = Session.getActiveSession();
if(activeSession.getState().isOpened()){
Request request = Request.newMyFriendsRequest(activeSession,
new GraphUserListCallback(){
#Override
public void onCompleted(List<GraphUser> users, Response response){
GraphUser user = users.get(0);
JSONObject friendLikes = user.getInnerJSONObject();
try {
JSONArray data = friendLikes.getJSONObject("friends").getJSONArray("data");
Log.i("JSON", friendLikes.toString());
addInterests(data, 0);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle bundle = new Bundle();
bundle.putString("fields", "friends.uid("+friendID+").fields(movies)");
request.setParameters(bundle);
request.executeAsync();
All times I execute this code I receive the following error from JSON:
W/System.err(694): org.json.JSONException: No value for friends.
If this isn't the way to get friend interests using GraphAPI, what do I need to do to get these values?
[EDIT] Solved posting friends_likes permission on Login. Permission is not sended inside Request.
I modified a bit my solution. If anyone is interested:
String fqlQuery = "SELECT music, books, movies FROM user where uid ="+friendID;
Bundle bundle = new Bundle();
bundle.putString("q", fqlQuery);
Request request = new Request(activeSession, "/fql", bundle, HttpMethod.GET,
new Request.Callback() {
#Override
public void onCompleted(Response response) {
// TODO Auto-generated method stub
Log.i("INFO", response.toString());
}
});
Request.executeBatchAsync(request);

posting on the facebook app page

I'm able to post to a users wall using android application. but i have another request to post to a specific app page (which is created for the same app). But i couldn't find any resource regarding this...
can anyone help how to archive this...
So far to share on users wall this piece of code is working..
private void postOnFB(byte[] data) {
try {
Log.v("postImage", "in");
Bundle params = new Bundle();
params.putString("description", "Play this awesome bible game..");
params.putByteArray("picture", data);
params.putString("message", facebookPostingMessage
+ "\n http://www.momaco.lk/");
mAsyncFacebookRunner.request("me/photos", params, "POST",
new SampleUploadListener(), null);
} catch (Exception e) {
// Do nothing only to catch exception
e.printStackTrace();
}
}
Please can some one help me on this...
You can post to the app page's wall by issuing an HTTP POST request to the app page's feed connection:
http://graph.facebook.com/APP_PAGE_ID/feed
That is, you code should read
mAsyncFacebookRunner.request(APP_PAGE_ID + "/feed", params, "POST",
new SampleUploadListener(), null);
Note that its the app's page id you post to, not the app id.

Sending message to a friend on facebook Android

I am developing an application which is able to let a user send a message to a friend on facebook. I have looked at Facebook API, Hackbook folder. I used the following code, but it did not work. It seems to ask me to implement a new dialog for it.
Bundle params = new Bundle();
params.putString("caption", app_name);
params.putString("picture", picture);
dialog(MyClass.this, "send", params, new UpdateStatusListener());
Any help is very appreciated !
Check this Snippet for Posting on Friend's wall :
try{
parameters.putString("message", "Text is lame. Listen up:");
parameters.putString("target_id", "XXXXX"); // target Id in which you need to Post
parameters.putString("method", "stream.publish");
String response = authenticatedFacebook.request(parameters);
Log.v("response", response);
}
catch(Exception e){}

Facebook post on Friends wall in Android

I would like to post a picture to my friend's wall.
But I logged in to my account say test#gmail.com, but now I want to post on to any of my friend wall.
I am having all my friends id and Name.
Is it possible to Post a picture in friends wall by logged to my account? If so how is it possible?
try{
Bundle parameters = new Bundle();
JSONObject attachment = new JSONObject();
try {
attachment.put("message", "Messages");
attachment.put("name", "Get utellit to send messages like this!");
attachment.put("href", link);
} catch (JSONException e) {
}
parameters.putString("attachment", attachment.toString());
parameters.putString("message", "Text is lame. Listen up:");
parameters.putString("target_id", "XXXXX"); // target Id in which you need to Post
parameters.putString("method", "stream.publish");
String response = authenticatedFacebook.request(parameters);
Log.v("response", response);
}
catch(Exception e){}
The Facebook SDK in general, as well as the one for Android, allows you to do so. See the example code here.

Categories

Resources