You can download facebook sdk .
https://www.dropbox.com/s/5woagok3tvq2pui/FacebookSDK.rar
private void FaceBook_Sharing()
{
final Bundle params = new Bundle();
params.putString("name", "Title");
params.putString("description" ,"Description");
params.putString("picture"," Image Url");
if (Session.getActiveSession() == null|| Session.getActiveSession(). isClosed())
{
Session.openActiveSession( this, true, new StatusCallback()
{
private List<String> permissions;
@SuppressWarnings(" deprecation")
@Override
public void call(Session session, SessionState state,Exception exception)
{
System.out.println("State= " + session.isOpened());
if (session.isOpened())
{
try
{
permissions = session.getPermissions();
if (!permissions.contains(" publish_actions")) {
Log.i("System out","come for permition in");
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest( MainActivity.this, Arrays.asList("",""))
.setDefaultAudience( SessionDefaultAudience. FRIENDS);
//session. requestNewPublishPermissions( newPermissionsRequest);
}
}
catch (Exception e)
{
// TODO: handle exception
}
Log.i("System out","come for permition else");
System.out.println("Token=" + session.getAccessToken());
facebook.setAccessToken( session.getAccessToken());
session = Session.getActiveSession();
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder( MainActivity.this,session, params)). setOnCompleteListener(new OnCompleteListener()
{
@Override
public void onComplete(Bundle values,FacebookException error)
{
if (error == null)
{
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(MainActivity. this, "Posted successfully.", Toast.LENGTH_LONG).show();
}
else
{
// User clicked the Cancel button
Toast.makeText(MainActivity. this, "Publish cancelled", Toast.LENGTH_SHORT).show();
}
}
else if (error instanceof FacebookOperationCanceledExcep tion)
{
// User clicked the "x" button
Toast.makeText(MainActivity. this, "Publish cancelled",Toast.LENGTH_SHORT) .show();
}
else
{
// Generic, ex: network error
Toast.makeText(MainActivity. this, "Error posting story", Toast.LENGTH_SHORT).show();
}
}
})
.build();
feedDialog.show();
}
if (exception != null)
{
System.out.println("Some thing bad happened!");
exception.printStackTrace();
}
}
});
}
}
Thanks for sharing this code
ReplyDelete