status update on facebook without dialog Android - android

Im using facebook-android-sdk-3.5.2, I want to post a message on facebook wall by clicking on button without showing dialog, I have tried many codes, some are saying "to post without dialog use Graph Api" but I don't understand how to use graph api. Some hav also given this solution which not work with me and not showing any error.
String message = "weLcom3";
Bundle parameterss = new Bundle();
parameterss.putString("message", message);
try {
fb.request("feed", parameterss, "POST");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Try this it may help you, I am able to post without dialog box to facebook by this
String response;
try {
String msg="your message to be posted";
response = facebook.request("me");
Bundle b=new Bundle();
b.putString("message",msg);
b.putString("description", "Test test test");
response=facebook.request("me/feed",b, "Post");
if (response == null || response.equals("") || response.equals("false"))
{
System.out.println("Blank Response");
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

This is what I use:
Request request = new Request(session, "me/feed", parameterss,
HttpMethod.POST, checkincallback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
Request.Callback checkincallback = new Request.Callback() {
public void onCompleted(Response response) {
FacebookRequestError error = response.getError();
if (error != null) {
// error
} else {
//succeeded
}
}
};
}

Related

How to post on Facebook page's wall in Android?

Hi I want to post any message or link to an Facebook page.What I have tried is this.
void postInfo()
{
try
{
Bundle parameters = new Bundle();
parameters.putString("message", messageFacebook);
parameters.putString("name", "Test Name");
parameters.putString("link", "http://www.mylink.com/");
parameters.putString("picture", imageUrl);
parameters.putString("display", "page");
String responsePost = facebook.request("me/feed", parameters, "POST");
String responsePagePost = facebook.request(FACEBOOK_PAGE_ID+"/feed", parameters, "POST");
Log.i(TAG, "responsePost = " + responsePost);
Log.i(TAG, "responsePagePost = " + responsePagePost);
} catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
What I am doing is I am posting a link to user's wall & also to my app's Facebook page.
This code works fine but problem is on Facebook page.The link which I post on Facebook page doesn't appear on page's wall but it appears on page's timeline in a box titled "Recent Posts by Others on MyApp Page".
I want the post should appear on wall rather than timeline.
What should I do I am not getting please help.
Facebook has changed all it's profiles to timelines now. Any facebook page will show posts by others as "Recent Posts by Others on MyApp Page". This behavior is controlled by facebook and not by your app. There is nothing you can do in this case.
Try this :
void postInfo()
{
try
{
Bundle parameters = new Bundle();
parameters.putString("message", messageFacebook);
parameters.putString("name", "Test Name");
parameters.putString("link", "http://www.mylink.com/");
parameters.putString("picture", imageUrl);
parameters.putString("display", "page");
facebook.dialog(this, "stream.publish", params,
new DialogListener() {
public void onFacebookError(FacebookError e) {
e.printStackTrace();
}
public void onError(DialogError e) {
// TODO Auto-generated method stub
e.printStackTrace();
}
public void onComplete(Bundle values) {
}
public void onCancel() {
}
});
} catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}

Authentication error when connect to Google Tasks API by HttpClient

I am trying to connect to the Google Tasks by using HttpClient but always get "Unauthorised HttpResponseException".
Here is my code inside the "run" method of the AccountManagerCallback
#Override
public void run(AccountManagerFuture<Bundle> result) {
// Get the result of the operation from the AccountManagerFuture.
Bundle bundle;
try {
bundle = result.getResult();
token = bundle.getString(AccountManager.KEY_AUTHTOKEN);
Log.i("#######", token); // token does have value
String url = "https://www.googleapis.com/tasks/v1/users/#me/lists?key=" + your_api_key;
HttpGet getRequest = new HttpGet(url);
getRequest.addHeader("client_id", your_client_id);
getRequest.addHeader("client_secret", your_client_secret);
getRequest.addHeader("Authorization", "OAuth " + token);
HttpClient httpclient = new DefaultHttpClient();
String responseBody = httpclient.execute(getRequest, new BasicResponseHandler()); // exception raised here
Log.i("###", responseBody); // cannot get the response here
} catch (OperationCanceledException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AuthenticatorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I am using Google APIs Level 10 emulator which does have access to the internet and I did add an google account into it.
Appreciate for any helps or suggestions to make my code work. Thanks.

me/feed not posting to facebook wall

My facebook wall posting AND checkins were working until last week... Now they have stopped working. it is really strange... I am not sure what is causing it.
I can login to facebook fine. That is proven because I can receive my facebook profile picture.
At the top of the class extending activity I have specified these fields:
private static final String APP_ID = "286529654765268";
private static final String[] PERMISSIONS = {"publish_stream", "publish_actions", "publish_checkins", "create_event"};
private static final String TOKEN = "access_token";
private static final String EXPIRES = "expires_in";
private static final String KEY = "facebook-credentials";
private Facebook facebook = new Facebook(APP_ID);
I use the facebook object throughout my class.
This is how I post a message:
defaultMessage = edittext.getText().toString();
String response = null;
try{
SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences("settings", 0);
String imageUrl = "www.somesite.com/somejpg.jpg";
Bundle params = new Bundle();
params.putString(Facebook.TOKEN, facebook.getAccessToken());
params.putString("caption", defaultMessage);
params.putString("description", "a description");
params.putString("picture", imageUrl);
params.putString("name", "A Name");
//
response = facebook.request("me/feed", params, "POST");
facebook.request("me/feed", params, "POST");
} catch(Exception e){
e.getStackTrace();
}
if(response != "false" || response != null){
Toast.makeText(getApplicationContext(), "Status Updated Successfully!", Toast.LENGTH_LONG).show();
Log.e("facebook response", response);
}
I authorize onCreate. Here is where I do it:
public void facebookAuthorize(){
facebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH, new DialogListener() {
#Override
public void onComplete(Bundle values) {
String me = null;
String id = null;
try {
me = facebook.request("me");
} catch (MalformedURLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
JSONObject json_id = null;
try {
json_id = new JSONObject(me);
} catch (org.json.JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
id = json_id.getString("id");
} catch (org.json.JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.e("Id", id);
URL img_value = null;
try {
img_value = new URL("http://graph.facebook.com/"+id+"/picture?type=large");
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Bitmap mIcon1 = null;
try {
mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(mIcon1 != null){
badge.setImageBitmap(mIcon1);
}
Toast.makeText(getApplicationContext(), "Successfully logged in!", Toast.LENGTH_LONG).show();
}
#Override
public void onFacebookError(FacebookError error) {}
#Override
public void onCancel() {}
#Override
public void onError(com.facebook.android.DialogError e) {
// TODO Auto-generated method stub
}
});
if(restore(facebook, getApplicationContext())){
//authorize the user.
facebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH, new DialogListener() {
#Override
public void onComplete(Bundle values) {
Toast.makeText(getApplicationContext(), "Successfully Logged In to facebook!", Toast.LENGTH_LONG).show();
}
#Override
public void onCancel() {}
#Override
public void onFacebookError(com.facebook.android.FacebookError e) {
e.printStackTrace();
if(facebook.isSessionValid()){
Toast.makeText(getApplicationContext(), "Successfully Logged in to Facebook!", Toast.LENGTH_LONG).show();
// download the users avatar
}
else{
Log.e("FACEBOOK FAIL", "Facebook has epicly failed with an error in onCreate in Social Sharing or you are logged in already");
}
}
#Override
public void onError(com.facebook.android.DialogError e) {
// TODO Auto-generated method stub
}
});
} else { save(facebook, getApplicationContext()); }
}
I do not get an error. It appears to work but does not appear on my wall.
I get a facebook response with a post id too... The application is not blocked from posting on my profile.
Im at my wits end trying to figure out the issue. Any help would be great!.
I get a facebook response with a post id too...
What response do you get if you try to look up your post via that id?
If you can see your post this way, then it’s just not displayed on your wall (for reasons such as hiding/deleting previous posts, negative app feedback, …)

facebook status update

I am having problem in updating status on facebook. I am using Facebook sdk, the problem is that my status is getting post but not showing text. Here is my code ---->
public class NetRockersUpdate extends AsyncTask{
#Override
protected String doInBackground(String... msg) {
// TODO Auto-generated method stub
nra = (NetRockersApp)getApplication();
String result = "Status Posted Successfully";
Bundle parameters = new Bundle();
parameters.putString("test", msg[0]);
parameters.putString("method", "stream.publish");
try {
nra.facebook.request(parameters);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
}
Check all the below post : I explained how to Post on User wall:
Post on User's Facebook Wall
Post to user Wall with Description,title,caption and link
Post on Wall..
you don't have a "message" key in your parameter.

StreamCorruptedException with Android-Java Communication

I need to send serialized Data from an Android Device to a Java Server.
I don't know why, but the communication seems to be very unstable. In the Debugger, the java.io.StreamCorruptedException: is thrown immediately after the start. not one Object is passing.
Without the debugger, nearly 10 Messages are passed until the same Exception is thrown.
Anyone got an idea, please help me:)
Thank you!
Fabian
Exception:
java.io.StreamCorruptedException: invalid type code: 2F
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at androidAnbindung.AndroidVerwalter.run(AndroidVerwalter.java:114)
java-code:
public void Nachrichtenaustausch(){
port ++;
try {
serverSocket = new java.net.ServerSocket(port);
System.out.println("Warte auf 2. Verbindungsaufbau...");
client = serverSocket.accept();
System.out.println("Verbindung 2 ist eingegangen...");
in = new ObjectInputStream(new ObjectInputStream(client.getInputStream()));
Nachricht n;
// starte den regulären Verkehr mit dem Androidgerät
new Thread(this).start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
#Override
public void run() {
Nachricht speicher;
while (true) {
try {
speicher = (Nachricht) in.readObject();
if (speicher != null) {
System.out.println(speicher.getName()+"..............................."+speicher.getWerte().get(0));
}synchronized (objekliste) {
for (AndroidObject ao : this.objekliste) {
if (speicher.getName().equals(ao.name)) {
ao.abstrakter_Wert = speicher.getAktuellerWert();
if (speicher.getWerte()!=null) {
ao.werte = speicher.getWerte();
}
}
}
}
Thread.sleep(50);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (Exception e) {
// TODO: handle exception
}
}
}
and the android thread:
#Override
public void run() {
// TODO Auto-generated method stub
try {
while (true) {
if (!nachrichtenliste.isEmpty()) {
Nachricht speicher = nachrichtenliste.get(0);
try {
out.writeObject(speicher);
out.flush();
synchronized (nachrichtenliste) {
nachrichtenliste.remove(speicher);
}
} catch (IOException e) {
e.printStackTrace();
}
}
Thread.sleep(50);
handler.post(this);
}
} catch (Exception e) {
// TODO: handle exception
}
}
I can imagine that Android and Java are not exactly serialization compatible here. So that one side sends a code that the other does not expect.
I'd rather go with some more textual protocol (json, xml) here, than with serialization.

Categories

Resources