gpt4 book ai didi

android - 登录 facebook android 时授权对话框出现两次

转载 作者:太空狗 更新时间:2023-10-29 14:16:22 29 4
gpt4 key购买 nike

我是 facebook 开发的新手。我想登录facebook 并允许用户允许我的应用程序发布照片和内容。但是当用户 login 成功时,他会两次显示授权对话框。这是我的代码

Session.openActiveSession(this, true, new Session.StatusCallback() {

// callback when session changes state
@Override
public void call(Session session, SessionState state,
Exception exception) {

if (session.isOpened()) {
Log.d("", "usman: session is opened");
// make request to the /me API

Request.executeMeRequestAsync(session,
new Request.GraphUserCallback() {

// callback after Graph API response with
// user
// object
@Override
public void onCompleted(GraphUser user,
Response response) {
Log.d("", "onCompleted called");
if (user != null) {
// TextView welcome = (TextView)
// findViewById(R.id.welcome);
Log.d(MyConstants.TAG,
"facebook Hello : "
+ user.getName() + "!");

publishStory();
//isShared = true;

} else {
Toast.makeText(
getApplicationContext(),
"Unable to Post,Try Again later",
Toast.LENGTH_LONG).show();
}
}
});

} else {
Log.d("", "usman: Session is not open");
}
}
});

private void publishStory() {
Log.d("", "usman: in 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;
}

FileInputStream fis = null;
try {
fis = new FileInputStream(fileImage);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Bitmap bi = BitmapFactory.decodeStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] data = baos.toByteArray();

Bundle postParams = new Bundle();

postParams.putString("name", "London For Less Postcard");
postParams.putString("caption",
"Build great social apps and get more installs.");
postParams
.putString(
"description",
"The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");

postParams.putByteArray("picture", data);

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", "JSON error " + e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
Toast.makeText(
SendPostCardActivity.this
.getApplicationContext(),
error.getErrorMessage(), Toast.LENGTH_SHORT)
.show();
Log.d("", "usman: Error");
} else {
Toast.makeText(
SendPostCardActivity.this
.getApplicationContext(),
"Posted on facebook wall successfully",
Toast.LENGTH_LONG).show();
Log.d("", "usman: Finish");
finish();
}
}
};

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

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

}

最佳答案

对我来说,当我使用 Facebook 按钮单击“登录”时,Facebook 登录对话框也会显示两次。

我刚刚更改了 Facebook 默认按钮并使用普通按钮,带有 Facebook 按钮背景,现在登录页面只显示一次。

Facebook 默认按钮显示正常和发布权限的登录页面。我不知道细节,但这对我有用。

关于android - 登录 facebook android 时授权对话框出现两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21624842/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com