我正在尝试在Facebook上分享一些细节,它适用于某些用户但不适用于所有用户,它会提供所需发布权限的错误。
void shareEventDetailsOnFacebook() {
try {
if (Utilities.getDataFromPreferences(WhosGoingActivity.this, "SAHRE_ON_FACEBOOK", "ON").equals("ON")) {
Logger.logger(" FriendsDetailsActivity ", "response =======" + Session.getActiveSession().getPermissions().toString());
Bundle params = new Bundle();
params.putString("message", "I have booked!" + "\n\nEvent:" + Utilities.getDataFromPreferences(WhosGoingActivity.this, "EVENT_NAME", "-1") + "\nOn:" + Utilities.getDataFromPreferences(WhosGoingActivity.this, "EVENT_DATE", "-1") + "," + Utilities.getDataFromPreferences(WhosGoingActivity.this, "EVENT_TIME", "-1");
params.putString("name", Utilities.getDataFromPreferences(WhosGoingActivity.this, "EVENT_NAME", "-1"));
params.putString("picture", Utilities.getDataFromPreferences(WhosGoingActivity.this, "EVENT_IMAGE", "-1"));
params.putString("link", "www.google.com");
Logger.logger("message", "I have booked a night out!" + "\n\nEvent:" + Utilities.getDataFromPreferences(WhosGoingActivity.this, "EVENT_NAME", "-1") + "\nOn:" + Utilities.getDataFromPreferences(WhosGoingActivity.this, "EVENT_DATE", "-1") + "," + Utilities.getDataFromPreferences(WhosGoingActivity.this, "EVENT_TIME", "-1")+"#nightup");
facebookID = "";
for (int i = 0; i < listFaceBookID.size(); i++) {
facebookID = facebookID + listFaceBookID.get(i) + ",";
}
facebookID = removeCommaAtEndOfString(facebookID);
Logger.logger("FacebookIds ==================== " + facebookID);
params.putString("tags", facebookID);
params.putString("place", Utilities.getDataFromPreferences(WhosGoingActivity.this, "PAGE_ID", "-1"));
Logger.logger(" FriendsDetailsActivity permissions ", "response =======" + Session.getActiveSession().getPermissions().toString());
Request request = new Request(Session.getActiveSession(), "me/feed", params, HttpMethod.POST, new Request.Callback() {
@Override
public void onCompleted(Response response) {
Logger.logger(" invite() FriendsDetailsActivity invite() ", "response =======" + response.toString());
}
});
Request.executeBatchAsync(request);
}
} catch (Exception e) {
e.printStackTrace();
}
}
请你帮我..
答案 0 :(得分:0)
以下是Facebook共享的示例代码,如果尚未授予,则会提示用户发布权限!
private void shareOnFacebook()
{
Session session = Session.getActiveSession();
if(session.isOpened())
{
List<String> permissions = session.getPermissions();
if(! isSubsetOf(PERMISSIONS, permissions))
{
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
final ProgressDialog progressDialog = ProgressDialog.show(this, "", getString(R.string.please_wait));
Bundle postParams = new Bundle();
postParams.putString("name", "Cabit");
postParams.putString("caption", "Ready when you are");
postParams.putString("description", getString(R.string.sharing_text));
postParams.putString("link", "http://s3technology.net/");
postParams.putString("picture", "");
Request.Callback callback = new Request.Callback()
{
@Override
public void onCompleted(Response response)
{
progressDialog.dismiss();
System.out.println("Response"+response);
GraphObject graphObject = response.getGraphObject();
System.out.println("response object:"+graphObject);
if(graphObject != null)
{
try
{
JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
Log.v("callback completed", ""+response.getGraphObject());
String postId = null;
postId = graphResponse.getString("id");
Log.v("postId", postId);
}
catch (JSONException e)
{
Log.i("shareOnFacebook", "JSON error "+ e.getMessage());
}
FacebookRequestError error = response.getError();
if(error != null)
{
toastMessage.showToast(error.getErrorMessage());
}
else
{
toastMessage.showToast("Shared on Facebook...");
}
}
else
{
toastMessage.showToast(getString(R.string.connection_error));
}
}
};
Request request = new Request(session, "me/feed", postParams, HttpMethod.POST, callback);
RequestAsyncTask requestAsyncTask = new RequestAsyncTask(request);
requestAsyncTask.execute();
}
else
{
loginViaFacebook();
}
}
private boolean isSubsetOf(Collection<String> subset, Collection<String> superset)
{
for(String string : subset)
{
if(! superset.contains(string))
{
return false;
}
}
return true;
}
private void onSessionStateChange(Session session, SessionState state, Exception exception)
{
Log.d("onSessionStateChanged", state.name());
if(pendingPublishReauthorization && state.equals(SessionState.OPENED_TOKEN_UPDATED))
{
pendingPublishReauthorization = false;
shareOnFacebook();
}
if(state.equals(SessionState.OPENED))
{
shareOnFacebook();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if(Session.getActiveSession() != null)
{
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
Log.d("onACtivityResult", "Entered");
}
}