本文介绍了怎么可以发布在Facebook上的android应用程序与API墙没有检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
只需调用 publishStory(StringYouNeed,StringYouNeed,StringYouNeed);
并在您的活动/片段中实现:
private void publishStory(String hash,String title,String user){
会话session = Session.getActiveSession();
if(session!= null){
//检查发布权限
列表< String> permissions = session.getPermissions();
if(!isSubsetOf(PERMISSIONS,permissions)){
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session
.NewPermissionsRequest(getActivity(),PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
返回;
}
Bundle postParams = new Bundle();
postParams.putString(name,title);
postParams.putString(caption,bla bla);
postParams.putString(description,bla bla);
postParams.putString(link,http://blabla.com/\"+hash);
Request.Callback callback = new Request.Callback(){
public void onCompleted(Response response){
JSONObject graphResponse = response
.getGraphObject()
.getInnerJSONObject();
String postId = null;
try {
postId = graphResponse.getString(id);
} catch(JSONException e){
Log.i(TAG,
JSON error+ e.getMessage());
}
FacebookRequestError error = response.getError();
if(error!= null){
debug.print(erreur);
}
}
};
请求请求=新请求(会话,我/ feed,postParams,
HttpMethod.POST,回调);
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;
}
}
返回true;
}
非常适合我,希望这个帮助。
How can l post on facebook from android app with API wall without checking (displaying "post to wall" screen from facebook)
解决方案
Just call publishStory(StringYouNeed,StringYouNeed,StringYouNeed);
And implement this in your activity / Fragment :
private void publishStory(String hash, String title, String user) {
Session session = Session.getActiveSession();
if (session != null){
// Check for publish permissions
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session
.NewPermissionsRequest(getActivity(), PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
Bundle postParams = new Bundle();
postParams.putString("name", title);
postParams.putString("caption", "bla bla");
postParams.putString("description", "bla bla");
postParams.putString("link", "http://blabla.com/"+hash);
Request.Callback callback= new Request.Callback() {
public void onCompleted(Response response) {
JSONObject graphResponse = response
.getGraphObject()
.getInnerJSONObject();
String postId = null;
try {
postId = graphResponse.getString("id");
} catch (JSONException e) {
Log.i(TAG,
"JSON error "+ e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
debug.print("erreur");
}
}
};
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;
}
Works perfect for me, hope this help.
这篇关于怎么可以发布在Facebook上的android应用程序与API墙没有检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!