In Facebook 2.5 graph API whenever you post a publish request you just have to call the request method like this -
Util.parseJson(facebook.request("me/photos", parameters,"POST"));
Facebook will automatically publish the photo (or text) if you are already authorized.
But in new graph API 3.0 every time I send a request, Facebook opens the authorize dialog. I am able to publish photos and videos but I don't want to open the dialog if the session is already open after authorization. This is my code -
private void uploadVideo() {
final Session session = Session.getActiveSession();
final Request request;
if(session.isOpened())
{
OpenRequest openRequest = new OpenRequest(getActivity());
openRequest.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
openRequest.setCallback(null);
List<String> PERMISSIONS = new ArrayList<String>();
PERMISSIONS.add("publish_stream");
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(getActivity(), PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
Callback callback = new Callback() {
@Override
public void onCompleted(Response response) {
System.out.println(response.toString());
}
};
File file = new File(Environment.getExternalStorageDirectory()+"/123.mp4");
if(file.exists())
{
try {
request = Request.newUploadVideoRequest(session, file, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
}
UPDATE
I tried replacing these two lines -
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(getActivity(), PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
with this-
openRequest.setPermissions(PERMISSIONS);
By doing this its not showing authorization dialog but the success is rate 2 out 3. Sometimes the response message state -
Unexpected error occurs.