Post on Facebook wall using Facebook Android SDK without opening dialog box
i applied following code and could successfully posted my message on wall.
public void postOnWall(String msg) {
Log.d("Tests", "Testing graph API wall post");
try {
String response = mFacebook.request("me");
Bundle parameters = new Bundle();
parameters.putString("message", msg);
parameters.putString("description", "test test test");
response = mFacebook.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();
}
}
Post on Facebook wall without showing dialog on android
I found out what the problem was. I was not asking the right permissions and the graph path was also wrong. The right method is :
public static void PublishToFeedInBackground()
{
final Bundle _postParameter = new Bundle();
_postParameter.putString("name", name);
_postParameter.putString("link", link);
_postParameter.putString("picture", link_to_image);
_postParameter.putString("caption", caption);
_postParameter.putString("description", description);
final List<String> PERMISSIONS = Arrays.asList("publish_stream");
if (Session.getActiveSession() != null)
{
NewPermissionsRequest reauthRequest = new Session.NewPermissionsRequest(this.GetContext(), PERMISSIONS);
Session.getActiveSession().requestNewPublishPermissions(reauthRequest);
}
this.runOnUiThread(new Runnable()
{
@Override
public void run()
{
Request request = new Request(Session.getActiveSession(), "feed", _postParameter, HttpMethod.POST);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
});
}
Android Facebook SDK : post message without showing facebook page
Its not possible.
You must have to login into facebook accountto post the message on Facebook.
Your requirement is only possible if you stored the facebook id and password staticaly in to the application.
Well but there is one alternate of it. If you use facebook sdk to implement the post message on Facebook then it may help you. With using that you can only able to get the facebook login screen once. If user has registered with that login id and password then it will never come again and simple send varification toast message that the message is posted on facebook.
For the above example refer this examples.
- Example 1
- Example 2
- Demo Example
- Example 4
Hope it will help you. If not then let me know.
Enjoy. :)
Updated
For to post the static message on facebook, do like below after integrating the Facebook sdk in to the project:
System.out.println("Message is: "+postMessage); // My static post message
facebook.authorize(MainActivityPage.this, new String[]{ "user_photos,publish_checkins,publish_actions,publish_stream"},new DialogListener() {
@Override
public void onComplete(Bundle values) {
Bundle params = new Bundle();
params.putString(Facebook.TOKEN, facebook.getAccessToken());
params.putString("message", postMessage);
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request("me/feed", params, "POST", new SampleUploadListener(),null);
Toast.makeText(getApplicationContext(), "Message Posted on Facebook.", Toast.LENGTH_SHORT).show();
}
@Override
public void onFacebookError(FacebookError error) {}
@Override
public void onError(DialogError e) {}
@Override
public void onCancel() {}
});
post a message to facebook wall from android studio project
post some predefined text
That part is impossible and not allowed, because:
Don't prefill captions, comments, messages, or the user message
parameter of posts with content a person didn’t create, even if the
person can edit or remove the content before sharing.
Source: https://developers.facebook.com/policy/
Obviously, you will never get the required permission (publish_actions
) approved for posting predefined text.
Related Topics
Android: Why Must Use Getbasecontext() Instead of This
Single Observable with Multiple Subscribers
How to Read Properties Defined in Local.Properties in Build.Gradle
Android: How Handle Message Error from the Server Using Volley
The Key Must Be an Application-Specific Resource Id
Android Getting an Image from Gallery Comes Rotated
When Should One Use Rxjava Observable and When Simple Callback on Android
Capture Picture Without Preview Using Camera2 API
Analyticsservice Not Registered in the App Manifest - Error
Android Toolbar: Small Title Text in Landscape Mode
Tiled Drawable Sometimes Stretches
Android: Sample Code to Connect to Vpn in Android 4.0 Using Vpnservice API
Writing Text File to Sd Card Fails
Scrolling Edittext Inside Scrollview
Ask for Password Before Uninstalling Application
Google Play Services Out of Date. Requires 11011000 But Found 10289574
Lame Mp3 Encoder Compile for Android
Moving or Copying Data from One Node to Another in Firebase Database