我在 facebook 上发布到群组,但我遇到了 2 个例外:
- 无法构造主体异常
- EOF异常
我尝试了很多解决方案,但没有成功。
包括这个:
System.setProperty("http.keepAlive", "false");
谢谢 :)
哦,这个运行在服务上运行。
Session session = Session.getActiveSession();
if(session==null) session = Session.openActiveSessionFromCache(getApplication());
if (session != null){
Log.d("Post Service", "session not null");
// Check for publish permissions
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
pendingPublishReauthorization = true;
Log.d("Post Service", "No Permissions to Post!");
return;
}
Bundle postParams = new Bundle();
postParams.putString("name", "AutoPost");
postParams.putString("message", this.post);
if(!this.piclink.equals(""))postParams.putString("picture",
this.piclink);
for(int i=0; i<this.groupsIds.length;i++){
Log.d("Post Service", "posting to: "+this.groupsIds[i]);
Request request = new Request(session, this.groupsIds[i]+"/feed", postParams,
HttpMethod.POST);
if(this.appStatus.isOnline(this.getApplicationContext())){
Response resp = request.executeAndWait();
if(resp.getError()!=null){
Log.d("Post Service", "POST ERROR: "+resp.getError().toString());
Log.d("Post Service", "POST EXECEPTION: "+resp.getError().getException().toString());
this.notifMyUser("Post failed!post error",resp.getError().toString());
this.notifMyUser("Post failed!post exeception",resp.getError().getException().toString());
this.write("ErrorLog", this.groupsIds[i]+ ": "+resp.getError().toString());
this.write("ErrorLog", this.groupsIds[i]+ ": "+resp.getError().getException().toString());
}
else{
JSONObject graphResponse = resp
.getGraphObject()
.getInnerJSONObject();
String postName = null;
try {
postName = graphResponse.getString("id");
Log.d("Post Service", "post successful to: "+postName.toString());
this.write("ErrorLog", "post successfuly to: "+postName.toString());
this.notifMyUser("Post-Success!","post successful to: "+postName.toString());
} catch (JSONException e) {
Log.i("Post Service: ",
"trying to post, JSON error "+ e.getMessage());
}
}
}
else {
this.notifMyUser("Post-NoConnection", "faild to post to "+ this.groupsIds[i]);
this.write("ErrorLog", "faild to post to "+ this.groupsIds[i]);
}
}
}
}