How to post a message on facebook friends wall in Android [duplicate] - android

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Facebook post on Friends wall in Android
I have made an app in which i am fetching list of my all FACEBOOK friends, now i want while i do click on any of the friend row then i will be able to post on his/her wall.
So what are the permissions i need to give and what type of code i need to write to do that,
Like: still i have given below permission and written below code onListItemClick
permissions :
mFacebook.authorize(main, new String[] { "publish_stream",
"friends_birthday", "friends_photos" }, new MyAuthorizeListener());
Code:
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
MyFriend friend = (MyFriend) this.getListAdapter().getItem(position);
}
I am fetching FbId, name, bday and picture
public class MyFriend {
private String fbID = " ";
private String name = " ";
private String bday = " ";
private String pic = " ";
}

Now on-wards you can not post to our friend's wall.
Because Facebook has removed the feature from its Graph Api, so that we cannot Post on Friend's Wall
thats why we can only post on our facebook wall only.

Feature of posting on friend's wall has been removed from the Facebook sdk.
Previously it could have been done by the following code as claimed by this post,
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){}

Related

How to share link via twitter in android?

In my app I need to share link for promo site via Facebook and twitter, in facebook we got something like "share dialog" or post bundle like
Request request = new Request(Session.getActiveSession(), "me/feed", bundle, HttpMethod.POST,
new Request.Callback(){
#Override
public void onCompleted(Response response) {
...
}
});
but there are no twitter sdk for android(trully I use twitter4j) and no way to post bundle
so how to tweet link via twitter?
If you send text with link like "Here is our link: http://stackoverflow.com" - twitter will understand it and get info from your link and show it - as I understand you need to see your recognized link in twitter feed.
To post link you can make intent like #Adrian Sicaru or create your own custom dialog using asynctask with twitter4j as you mention:
#Override
protected Bundle doInBackground(Bundle... params) {
Bundle args = params[0];
Bundle result = new Bundle();
String paramMessage = args.getString(MESSAGE);
String paramLink = args.getString(LINK);
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey("your ConsumerKey");
builder.setOAuthConsumerSecret("your ConsumerSecret");
String accessToken = "your Token";
String accessTokenSecret = "your Secret";
TwitterFactory factory = new TwitterFactory(builder.build());
mTwitter = factory.getInstance(new AccessToken(accessToken, accessTokenSecret));
try {
StatusUpdate status = new StatusUpdate(paramMessage);
if (paramLink != null) {
status = new StatusUpdate(paramMessage + " " + paramLink);
}
mTwitter.updateStatus(status);
} catch (TwitterException e) {
result.putString(RESULT_ERROR, e.getMessage());
}
return result;
}
You can do it via intent like this :
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
This will open a list with apps already installed that can answer the intent, like gmail, facebook and... twitter.
You can find more information here: http://developer.android.com/training/sharing/send.html
Also, if you want to directly call twitter and don't want to choose, have a look at this answer
Like #TribblerWare answered just write link in tweet and twitter recognized it.
By the way, you can use ASNE library for this - just authorize user and use requestPostLink with bundle as parameter
Bundle postParams = new Bundle();
postParams.putString(SocialNetwork.BUNDLE_LINK, link);
socialNetwork.requestPostLink(postParams, message, postingComplete);
more detailed you can see in tutorial

How to get email id from facebook login in android?

I am trying to integrate Facebook API for login functionality in android. I need email Id for respective user. I am getting JSON in response but It has no email Id.How can I achieve to get the email Id.
public void getProfileInformation() {
mAsyncRunner.request("me", new RequestListener() {
#Override
public void onComplete(String response, Object state) {
Log.d("Profile", response);
String json = response;
try {
// Facebook Profile JSON data
JSONObject profile = new JSONObject(json);
// getting name of the user
final String name = profile.getString("name");
// getting email of the user
final String email = profile.getString("email");
runOnUiThread(new Runnable() {
// Dayanand plzz check this log n let me know.
#Override
public void run() {
Toast.makeText(getApplicationContext(), "Name: " + name + "\nEmail: " + email, Toast.LENGTH_LONG).show();
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
Here is code, Where I am getting null in Toast. It goes to catch method.Please help
You have to ask for the permission : email from the user.
You need to ask for the email permission to the user, otherwise you can't get it.
Once the user grants you the permission, you'll see it when requesting for me.
See http://developers.facebook.com/docs/reference/login/email-permissions/
When you first time login at that time you are passing one permission array. so, you have to pass this array for email permission..
private String[] permissions = {"publish_stream","email","user_about_me","user_status"};

fbShare in android

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.

Creating a custom Wall Post with Facebook API on Android

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.

facebook sdk android wall post line break

I'm making an application that is posting some information to your facebook wall using facebook sdk for android. This works, but I can't seem to get new lines on the posts. I have tried \n but it doesent work. Any suggestions?
Here is my code:
Bundle parameters = new Bundle();
String temp = "";
for (int i = 0; i < mArrayAdapter.getCount(); i++){
temp = temp + mArrayAdapter.getItem(i) + "\n"; // Not working
}
parameters.putString("message", temp);
mFacebook.dialog(this, "stream.publish", parameters, new DialogListener());
Thanks,
James Ford
Hi James i have tried that before, even with html code but i think thats not possible.
The reason, Facebook must have a control to avoid blank spaces or line break on his posts.
New lines are not allowed in stream posts (the fact that you may have seen them in the past are bugs on facebook).
make use of JSON to post on facebook..
how? look here
STEPS :-
Step 1 :- At this link u will came to know how to use JSON for setting text to TEXTVIEW.
Step 2 :- May be this is not u r looking for :) assign the text of textview to some string
using GetText().ToString
Step 3 :- use this string to post to the facebook.
Step 4 :- I did the same after spending lot of time in googling and finally got the result
by using this trick. u can see my post that i posted during test here
Step 5 :- set the visibilty of this text box to gone using
tv.setVisibility(View.GONE)
And u r done with your posting to facebook..
let the facebook and textview handle how they manage spaces and new line character :D
Some Coding work for newbies like me...
I am posting it on click of button
1)
tv= (TextView)findViewById(R.id.tv);
click=(Button)findViewById(R.id.btn1);
click.setOnClickListener(mthdpost);
2) add on click event to this button
private View.OnClickListener mthdpost=new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
String json = "{"
+ " \"name\": \"myName\", "
+ " \"message\": [\"myMessage1\",\"myMessage2\"],"
+ " \"place\": \"myPlace\", "
+ " \"date\": \"thisDate\" "
+ "}";
/* Create a JSON object and parse the required values */
JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
String name = object.getString("name");
String place = object.getString("place");
String date = object.getString("date");
JSONArray message = object.getJSONArray("message");
String MessageToPost= null;
tv.setText("Name: "+ name +"\n\n");
tv.append("Place: "+ place +"\n\n");
tv.append("Date: "+ date +"\n\n");
/*JSONObject attachment = new JSONObject();
attachment.put("Name: ","\n\n");
attachment.put("Place: ","\n\n");
attachment.put("Date: ","\n\n");*/
for(int i=0;i<message.length();i++)
{
tv.append("Message: "+ message.getString(i) +"\n\n");
//attachment.put("Message: ","\n\n");
}
MessageToPost=tv.getText().toString();
postToWall(MessageToPost);// called the method having logic to post on wall and sending the textview text to to post as message
} catch (JSONException e)
{e.printStackTrace();
}
catch(Exception ex)
{ex.printStackTrace();}
}
};
3) method for posting the message
public void postToWall(String msg){
Log.d("Tests", "Testing graph API wall post");
try {
String response = facebook.request("me");
Bundle parameters = new Bundle();
//parameters.putString("message", msg.toString());
parameters.putString("message", msg);
parameters.putString("description", "test test test");
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();
}
}
HOPE IT WILL HELP :)
This worked for me:
StringBuilder messageData = new StringBuilder(title).append('\n')
.append('\n').append(message).append('\n').append('\n')
.append(description);
// Message
postParams.putString("message", messageData.toString());
This works:
Use this: <center></center>
Instead of a br or a newline, etc. You can only do one in a row (ie. you can't increase the spacing).

Categories

Resources