Android 앱을 통해 이야기를 게시하고 아래 코드를 사용하고 싶습니다. 세션 : 세션 : 보류중인 요청이있는 세션에 대한 새 권한을 요청하려고했습니다.
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(XXActivity.this, callback);
uiHelper.onCreate(savedInstanceState);
setContentView(R.layout.layoutAct);
...
...
...
publishAddCardStory();
...
}
@Override
public void onResume() {
super.onResume();
Session session = Session.getActiveSession();
if (session != null && (session.isOpened() || session.isClosed())) {
onSessionStateChange(session, session.getState(), null);
}
uiHelper.onResume();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(PENDING_PUBLISH_KEY, pendingPublishReauthorization);
uiHelper.onSaveInstanceState(outState);
}
private void publishAddCardStory() {
Session session = initFacebookSession(PopupAddCardSuccessActivity.this);
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;
}
Bundle params = new Bundle();
...
params.putString("message", msg);
params.putString("description", desc);
params.putString("link", LINK);
...
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("FB-Response",
"JSON error "+ e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
Toast.makeText(XXActivity.this
.getApplicationContext(),
getString(R.string.fb_post_fail),
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(XXActivity.this
.getApplicationContext(),
getString(R.string.fb_post_success),
Toast.LENGTH_LONG).show();
}
}
};
Request request = new Request(session, "me/feed", params,
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;
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
//shareButton.setVisibility(View.VISIBLE);
} else if (state.isClosed()) {
//shareButton.setVisibility(View.INVISIBLE);
}
}
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {
onSessionStateChange(session, state, exception);
}
};
private static Session initFacebookSession(Context context) {
Session session = Session.getActiveSession();
if (session != null)
return session;
if (session == null)
session = new Session(context);
return session;
}
는 언젠가 나는이 두 오류 ....
java.lang.UnsupportedOperationException가있어 시도가 보류중인 요청이있는 세션에 대한 새 권한을 요청 을 하였다.
또는 언젠가 ...
java.lang.UnsupportedOperationException가 : 세션 : 시도가 현재 열려 있지 않은 세션에 대한 새 권한을 요청 을 하였다.
의견을 보내 주시면 감사하겠습니다.