我正在尝试使用 Android 中的 Facebook SDK 3.0 在我的墙上发布状态更新。登录会话是完美的,除了发布部分,一切都很好。
在授予写到墙上的权限后。不贴到墙上。当我检查活动会话部分时。我在日志中得到 open_token_updated 而不是“OPENED” - 在授予写入权限之前 - 日志显示“OPENED”...
如果我关闭应用程序并再次加载应用程序,我可以看到“已打开”并且我可以发布到墙上。
这是我正在尝试的:
check.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
boolean login = false;
if (Session.getActiveSession() != null)
{
login = true;
}
Log.e ("Session Active?", "" + Session.getActiveSession().getState());
}
});
//POST WALL BUTTON
post.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
if(Session.getActiveSession() != null)
{
if(Session.getActiveSession().getState()==SessionState.OPENED)
publishStory();
}
}
});
这是发布方法
Session session = Session.getActiveSession();
if (session != null)
{
// Check for publish permissions
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions))
{
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
//return;
}
Log.e("after", "permissions");
Bundle postParams = new Bundle();
postParams.putString("name", "Sample Test from my app");
postParams.putString("caption", "The best");
postParams.putString("description","Testing how it works.");
postParams.putString("link", "http://www.google.com/");
postParams.putString("picture", "http://www.etftrends.com/wp-content/uploads/2012/07/blue_wave_of_water-wide.jpg");
Request.Callback callback = new Request.Callback()
{
public void onCompleted(Response response)
{
Log.e("post response",response.toString());
FacebookRequestError error = response.getError();
if (error != null)
{
Log.e ("No", "Not null");
}
else
{
Log.e ("No", "null");
JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
String postId = null;
try
{
postId = graphResponse.getString("id");
Toast.makeText(Sessionvalid.this, postId, Toast.LENGTH_LONG).show();
}
catch (JSONException e)
{
Log.i("JSON", "JSON error " + e.getMessage());
}
}
}
};
Request request = new Request(session, "me/feed", postParams, HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
子集方法
private boolean isSubsetOf(Collection<String> subset, Collection<String> superset)
{
for (String string : subset)
{
if (!superset.contains(string))
{
return false;
}
}
return true;
}
活动结果
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
我在这里做错了什么..不知道在哪里以及如何解决这个问题?