I am encountering a strange situation here.While posting to facebook I want my app to bypass the dialog the asks to write something and show my own customize dialog.For that reason I have to use "me/feed".The app works fine when I post something in the developers account.But when I try to post in some other account it sometime returns nothing or sometime returns:
08-21 12:26:29.332: D/Facebook-Util(6796): POST URL: https://graph.facebook.com/me/feed
08-21 12:26:29.722: D/Tests(6796): got response: {"error":{"message":"(#200) The user hasn't authorized the application to perform this action","type":"OAuthException","code":200}}
I am really confused about what mistake I am doing here.Why the message is not posting other than the developers account..?
This is my relevant code:
if (facebook.isSessionValid()) {
facebook.authorize(BoonDriveActivity.this,
new String[] { "publish_stream","publish_actions","manage_pages","status_update"},//This are the permissions
new DialogListener() {
@Override
public void onCancel() {
// Function to handle cancel event
}
@Override
public void onComplete(Bundle values) {
// Function to handle complete event
// Edit Preferences and update facebook acess_token
final SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token",
facebook.getAccessToken());
editor.putLong("access_expires",
facebook.getAccessExpires());
editor.commit();
LayoutInflater inflater=BoonDriveActivity.this.getLayoutInflater();
View layout=inflater.inflate(R.layout.createsharedialoglinkedin,null);
final AlertDialog d1 = new AlertDialog.Builder(BoonDriveActivity.this)
// Your other options here ...
.setView(layout)
.create();//My custom dialog
d1.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
d1.show();
lntxtfilename=(TextView)layout.findViewById(R.id.txtfilename);
lnetmessage=(EditText)layout.findViewById(R.id.et_message);
ln_btn_share=(Button)layout.findViewById(R.id.btn_share);
ln_btn_showlink=(Button)layout.findViewById(R.id.btn_showlink);
lnshowlink=(EditText)layout.findViewById(R.id.et_showlink);
ln_btn_share.setText("SHARE ON FACEBOOK");
ln_btn_showlink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ln_btn_showlink.setVisibility(View.GONE);
lnshowlink.setVisibility(View.VISIBLE);
lnshowlink.setText(finallink);
}
});
lntxtfilename.setText("Share"+" "+filename+" "+"with:");
ln_btn_share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//String s = ((GlobalFilename)BoonDriveActivity.this.getApplication()).getGlobalState();
if(lnetmessage.length()==0)
{
Toast.makeText(BoonDriveActivity.this,"Please enter message",Toast.LENGTH_LONG).show();
}
else{
String share1 = lnetmessage.getText().toString();
//String finalmsg=share1+"
"+s;
System.out.println("This is the final msg linkedin--->"+ finallink);
//lnetmessage.setText(finalmsg);
//postToWall();
postToWall(share1,finallink);
d1.dismiss();
}
}
});
}
@Override
public void onError(DialogError error) {
// Function to handle error
}
@Override
public void onFacebookError(FacebookError fberror) {
// Function to handle Facebook errors
}
});
}
}
I searched a lot about this,but couldn't find a solution.Please help.
I am using the following method to post to wall:
@SuppressWarnings("deprecation")
public void postToWall(String message,String link){
Bundle parameters = new Bundle();
parameters.putString("message", message+link);
// parameters.putString("link",link);
/* parameters.putString("description", "topic share");
parameters.putString("picture", link);*/
try {
String response = facebook.request("me");
facebook.request("me");
response = facebook.request("me/feed", parameters, "POST");
Log.d("Tests", "got response: " + response);
if (response == null || response.equals("") ||
response.equals("false")) {
showToast("Blank response.");
}
else {
showToast("Message posted to your facebook wall!");
}
} catch (Exception e) {
showToast("Failed to post to wall!");
e.printStackTrace();
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…