Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查Facebook帖子是否从Android应用程序成功发布_Android_Facebook_Api_Post_Sdk - Fatal编程技术网

检查Facebook帖子是否从Android应用程序成功发布

检查Facebook帖子是否从Android应用程序成功发布,android,facebook,api,post,sdk,Android,Facebook,Api,Post,Sdk,我使用的代码来自Facebook Android Sdk的到墙上的帖子。 我想有一些反馈,以了解该职位是否成功。 如何检查此项? 来自RequestAsyncTask对象的任何方法? 非常感谢 public void postOnMyWall(Context mycontext) { context = mycontext; pref = context.getSharedPreferences("AppPref", Context.MODE_PRIVATE); S

我使用的代码来自Facebook Android Sdk的到墙上的帖子。 我想有一些反馈,以了解该职位是否成功。 如何检查此项?
来自RequestAsyncTask对象的任何方法? 非常感谢

public void postOnMyWall(Context mycontext) {

    context = mycontext;  
    pref = context.getSharedPreferences("AppPref", Context.MODE_PRIVATE);
    String fbtoken = pref.getString("fbtoken", null);

     if(!fbtoken.equals("") && fbtoken != null) {

       Session session = Session.getActiveSession();

        if (session != null){

            Log.d("SOCIAL", "in posting wall, session is not null");

            // Check for publish permissions    
            List<String> permissions = session.getPermissions();
            if (!isSubsetOf(PERMISSIONS, permissions)) {
                pendingPublishReauthorization = true;
                Session.NewPermissionsRequest newPermissionsRequest = new Session
                        .NewPermissionsRequest(this, PERMISSIONS);
                session.requestNewPublishPermissions(newPermissionsRequest);
                return;
            }

            Bundle postParams = new Bundle();
            postParams.putString("name", "wef");
            postParams.putString("caption", "few");
            postParams.putString("description", "x");
            postParams.putString("link", "https://mylink.some");
            postParams.putString("picture", "https://mylink.some/img.png");

            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(activity.toString(),
                                "JSON error "+ e.getMessage());
                    */
                    }
                    FacebookRequestError error = response.getError();
                    if (error != null) {
                        //Toast.makeText(activity
                         //       .getApplicationContext(), 
                         //       "ERROR: " + error.getErrorMessage(),
                         //       Toast.LENGTH_SHORT).show();
                    } else {
                        /*
                        Toast.makeText(activity
                                .getApplicationContext(), 
                                "POSTED: " + postId,
                                Toast.LENGTH_LONG).show();
                                */
                    }
                }
            };


            Request request = new Request(session, "me/feed", postParams, HttpMethod.POST, callback);

            RequestAsyncTask task = new RequestAsyncTask(request);
            task.execute();

            Toast.makeText(context, "posted on Facebook", Toast.LENGTH_SHORT).show();


        } 

        } 


        else 
        {
            Log.d("SOCIAL","not logged in fb");
             Toast.makeText(context, R.string.facebook_login_request, Toast.LENGTH_SHORT).show();
        }



      }
public void postOnMyWall(Context mycontext){
上下文=mycontext;
pref=context.getSharedReferences(“AppPref”,context.MODE\u PRIVATE);
字符串fbtoken=pref.getString(“fbtoken”,null);
如果(!fbtoken.equals(“”&&fbtoken!=null){
Session=Session.getActiveSession();
if(会话!=null){
Log.d(“社交”,“在张贴墙中,会话不为空”);
//检查发布权限
List permissions=session.getPermissions();
如果(!isSubsetOf(权限、权限)){
pendingPublishReauthorization=真;
Session.newpermissions请求newpermissions请求=新会话
.NewPermissionsRequest(此,权限);
session.requestNewPublishPermissions(newPermissionsRequest);
返回;
}
Bundle postParams=新Bundle();
postParams.putString(“名称”、“wef”);
postParams.putString(“标题”,“很少”);
postParams.putString(“描述”,“x”);
postParams.putString(“链接”https://mylink.some");
postParams.putString(“图片”https://mylink.some/img.png");
Request.Callback=new Request.Callback(){
未完成公共无效(响应){
JSONObject graphResponse=响应
.getGraphObject()
.getInnerJSONObject();
字符串postId=null;
试一试{
postId=graphResponse.getString(“id”);
}捕获(JSONException e){
/*
Log.i(activity.toString(),
“JSON错误”+e.getMessage());
*/
}
FacebookRequestError=response.getError();
if(错误!=null){
//Toast.makeText(活动
//.getApplicationContext(),
//“错误:”+错误。getErrorMessage(),
//吐司。长度(短)。show();
}否则{
/*
Toast.makeText(活动
.getApplicationContext(),
“已发布:”+已发布,
Toast.LENGTH_LONG).show();
*/
}
}
};
请求=新请求(会话“me/feed”、后参数、HttpMethod.POST、回调);
RequestAsyncTask任务=新的RequestAsyncTask(请求);
task.execute();
Toast.makeText(上下文,“发布在Facebook上”,Toast.LENGTH_SHORT.show();
} 
} 
其他的
{
Log.d(“社交”、“未登录fb”);
Toast.makeText(context,R.string.facebook_login_请求,Toast.LENGTH_SHORT).show();
}
}
来自回调的
onCompleted(Response-Response)
方法接收
Response
类的实例。您可以使用此对象检查请求是否已成功处理。成功HTTP请求的响应代码应以2xx开头(例如200 OK、201 CREATED等)

如果由于某种原因失败,您可以检索详细错误,就像您在这一行中已经做的那样:

FacebookRequestError error = response.getError();
FacebookRequestError error = response.getError();