facebook Post auf Ihre Rechnung funktioniert nicht in android facebook sdk 3.0.2

ich bin versuchen, auf die post in facebook. login, veröffentlichen, ist die Erlaubnis zu arbeiten finefor das erste mal. wenn ich löschen Sie die app von facebook die web-es ist nicht mich Fragen, Neuinstallation login und das "Posten in Ihrem Namen" publish-permission-Bildschirm unten ist mein code Bitte um Hilfe, was ich gemacht mistike. Ich habe versucht viel, aber nicht richtig funktioniert.. vielen Dank für Ihre freundliche Beratung und so kann ich mich verbessern viel in android. Unten ist mein code...

public class FacebokView extends Activity {
static final String applicationId = String.valueOf(R.string.app_id); 
Session session;
private static final List<String> PERMISSIONS = Arrays.asList("publish_actions");
private static final String PENDING_PUBLISH_KEY = "pendingPublishReauthorization";
private boolean pendingPublishReauthorization = false;
private UiLifecycleHelper uiHelper;
//private StatusCallback statusCallback;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.faceok_view);
//create the session
this.session = createSession();
Log.i("session1--->", "session"+ session.isOpened());
//start Facebook Login
//Session.openActiveSession(this, true, new Session.StatusCallback() {
StatusCallback statusCallback = new StatusCallback() {
//callback when session changes state
@Override
public void call(Session session, SessionState state, Exception exception) {//READ
onSessionStateChange(session, state, exception);
Log.i("OPENED_TOKEN_UPDATED", state.equals(SessionState.OPENED_TOKEN_UPDATED) + "<<test");
if (session.isOpened() && session.getPermissions().contains("publish_actions")) {
Log.i("fb session1: publish_actions else if", session.getPermissions().contains("publish_actions") +"OPENED_TOKEN_UPDATED ----"+state.equals(SessionState.OPENED_TOKEN_UPDATED));
publishStory();
Log.i("session2--->", "session"+ session.isOpened());
} else if (session.isOpened()) {
Log.i("session3--->", "session"+ session.isOpened());
Log.i("fb session2: publish_actions else if", session.getPermissions().contains("publish_actions") +"OPENED_TOKEN_UPDATED ----"+state.equals(SessionState.OPENED_TOKEN_UPDATED));
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
pendingPublishReauthorization = true;
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(FacebookView.this, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
}
}   else if(session != null && session.getState() == SessionState.CLOSED_LOGIN_FAILED){
Log.i("fb session:", "not open");
Log.i("session4--->", "session"+ session.isOpened());
finish();
}
}
};
if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)){
Log.i("session5--->", "session"+ session.isOpened());
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
Log.i("CREATED_TOKEN_LOADED", "session"+ session.isOpened());
}else if (!session.isOpened() && !session.isClosed()) {
Log.i("session6--->", "session"+ session.isOpened());
OpenRequest req = new Session.OpenRequest(this);
req.setCallback(statusCallback);
session.openForRead(req);
} else {
Log.i("session7--->", "session"+ session.isOpened());
Session.openActiveSession(this, true, statusCallback);
}
} 
private void onSessionStateChange(Session session, SessionState state,Exception exception) {
if (state.isOpened()) {
if (pendingPublishReauthorization && state.equals(SessionState.OPENED_TOKEN_UPDATED)) {
Log.i("onSessionStateChange--->OPENED_TOKEN_UPDATED -->", state.equals(SessionState.OPENED_TOKEN_UPDATED) + "pendingPublishReauthorization-->" + pendingPublishReauthorization);
pendingPublishReauthorization = false;
publishStory();
Log.i("session12--->", "session"+ session.isOpened());
}
} else if (state.isClosed()) {
Log.i("session8--->", "session"+ session.isOpened());
//  shareButton.setVisibility(View.INVISIBLE);
}
}
protected void publishStory() {
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(this, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
//after login make request to the /me API
Bundle parameters = getIntent().getExtras();
String  facebookResponse = parameters.getString("facebookResponse");
Log.i("fbResp from server 1 publish_actions:", session.getPermissions().contains("publish_actions") + "*---facebookResponse----*"+ facebookResponse);
try {
JSONObject jsonObj = new JSONObject(facebookResponse);
parameters.putString("message", jsonObj.getString("MsgForFb"));
parameters.putString("name", jsonObj.getString("NameForFb"));
parameters.putString("link", jsonObj.getString("LinkForFb"));
parameters.putString("Description", jsonObj.getString("DescForFb"));
parameters.putString("picture", jsonObj.getString("PicForFb"));
} catch (JSONException e1) {
e1.printStackTrace();
}
Request.Callback callback = new Request.Callback() {
public void onCompleted(Response response) {
if(response.getGraphObject() != null) {
Log.i("fb Response - ", response.toString());
JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
String postId = null;
try {
postId = graphResponse.getString("id");
} catch (JSONException e) {
e.printStackTrace();
Log.e("FacebookView: callBack:", "JSON error : " + e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
Toast.makeText(FacebookView.this.getApplicationContext(), error.getErrorMessage(), Toast.LENGTH_LONG).show();
} else {
Log.i("FacebookView: Request.Callbak: postId = ", " "+postId);
}
}
}
};                    
Request request = new Request(session, "me/feed", parameters, HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
//callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
finish();
}
}
});
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
private Session createSession() {
Session activeSession = Session.getActiveSession();
if (activeSession == null || activeSession.getState().isClosed()) {
activeSession = new Session.Builder(this).setApplicationId(applicationId).build();
Session.setActiveSession(activeSession);
}
return activeSession;
}
private boolean isSubsetOf(Collection<String> subset, Collection<String> superset) {
for (String string : subset) {
if (!superset.contains(string)) {
return false;
}
}
return true;
}
}
  • Hi ich Habe dein code in der mu-app und es läuft gut , aber jetzt ist es bei mir zu einer java-Fehlermeldung.lang.UnsupportedOperationException: Session: ein Versuch wurde gemacht, um Anfrage neue Berechtigungen für eine Sitzung, die eine ausstehende Anforderung.
InformationsquelleAutor raki | 2013-07-26
Schreibe einen Kommentar