gpt4 book ai didi

android - 当在设备/模拟器上安装 Facebook 应用程序时,发布到用户 Facebook 墙无法正常工作

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:15:33 26 4
gpt4 key购买 nike

我构建了一个使用 this 的 Activity 实现(参见已接受的答案)以在用户的​​ Facebook 墙上发布状态更新。

如果模拟器/手机没有安装 facebook 应用程序,它也可以正常工作。

如果模拟器/手机安装了 facebook 应用程序,facebook 应用程序会加载登录屏幕,但在尝试登录后,facebook 应用程序就会消失,让我回到我的应用程序。

有没有人在安装facebook app的时候有过这样的经历?

我的代码:

public class AchievementActivity extends Activity implements DialogListener, OnClickListener{


private Facebook facebook;
Button facebookPostButton;
String defaultFacebookPost;

@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.achievements);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_layout);

View achievementDivider = (View)findViewById(R.id.achievementDivider);
int[] colors = {0, 0xff00ffff, 0};
achievementDivider.setBackgroundDrawable(new GradientDrawable(Orientation.RIGHT_LEFT, colors));

//get the title of the achievement from the intent that started this activity from the activity StatisticsActivity
String achievementTitleString = getIntent().getStringExtra("title");

String achievementTextToDisplay = getAchievementTextToDisplay(achievementTitleString);

defaultFacebookPost = getDefaultPost(achievementTitleString);

//ImageView achievementActivityAchievementBadgeImageView = (ImageView)findViewById(R.id.achievementActivityAchievementBadgeImageView);
TextView achievementActivityBadgeTitleTextView = (TextView)findViewById(R.id.achievementActivityBadgeTitleTextView);
achievementActivityBadgeTitleTextView.setText(achievementTitleString);

TextView achievementActivityAchievementText = (TextView)findViewById(R.id.achievementActivityAchievementText);
achievementActivityAchievementText.setText(achievementTextToDisplay);

facebookPostButton = (Button)findViewById(R.id.facebookPostButton);
facebookPostButton.setOnClickListener(this);


}

@Override
public void onComplete(Bundle values) {

if (values.isEmpty())
{
Toast.makeText(getApplicationContext(), "Empty", Toast.LENGTH_SHORT);

return;
}

if (!values.containsKey("post_id"))
{
try
{
Bundle parameters = new Bundle();
parameters.putString("message", defaultFacebookPost);// the message to post to the wall
facebook.dialog(AchievementActivity.this, "stream.publish", parameters, this);// "stream.publish" is an API call
}
catch (Exception e)
{
// TODO: handle exception
System.out.println(e.getMessage());
}
}

try
{
facebook.logout(getApplicationContext());
}
catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}

@Override
public void onFacebookError(FacebookError error)
{
Toast.makeText(AchievementActivity.this, "onFacebookError", Toast.LENGTH_LONG);
}

@Override
public void onError(DialogError e)
{
Toast.makeText(AchievementActivity.this, "onError", Toast.LENGTH_LONG);
}

@Override
public void onCancel()
{
Toast.makeText(AchievementActivity.this, "onCancel", Toast.LENGTH_LONG);
}

@Override
public void onClick(View v)
{
if (v == facebookPostButton)
{
facebook = new Facebook("my_facebook_api");
// replace APP_API_ID with your own
facebook.authorize(this, new String[] {"publish_stream", "read_stream", "offline_access"}, this);
}
}

private String getDefaultPost(String defaultTitleString)
{
//do some stuff here to get a string to post to wall

return defaultPost;
}

private String getAchievementTextToDisplay(String achievementTitleString) {
String achievementTextToDisplay = "DEFAULT";

//do some stuff here to get text to display in the activity
//this has nothing to do with the facebook post...

return achievementTextToDisplay;
}

}

Logcat 告诉我这个:

05-11 13:03:34.076: INFO/ActivityManager(98): Starting activity: Intent { cmp=com.facebook.katana/.ProxyAuth (has extras) }
05-11 13:03:34.246: INFO/ActivityManager(98): Displayed activity com.facebook.katana/.ProxyAuth: 158 ms (total 158 ms)
05-11 13:03:35.166: DEBUG/dalvikvm(12390): GC_FOR_MALLOC freed 6729 objects / 418424 bytes in 44ms
05-11 13:03:35.166: DEBUG/webviewglue(12390): nativeDestroy view: 0x527e20
05-11 13:03:35.166: DEBUG/NativeCrypto(12390): Freeing OpenSSL session

编辑:在过去一年不得不在多台机器上安装 android 开发平台并且在创建新的开发环境后 Facebook 总是有问题之后,我发现这个简单的答案可能是 Facebook 实现在一台设备上工作的原因并且不是另一个....

secret 的 Facebook API key (您在 developer.facebook.com 上列出的那个)对于您使用不同证书打包的应用程序的每个版本都是不同的。例如,假设您有两台开发机器。由于这两台机器都将使用不同的证书构建您的应用程序,因此您必须确保为每台机器生成一个 Facebook API key 并将它们列在 developer.facebook.com 上。

最佳答案

我找到了一个解决方法,但它不是目前最好的。

facebook.authorize(activity, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH, 
new LoginDialogListener());

如果设备上安装了官方 Facebook 应用程序,这将强制您的应用程序不使用 SSO。但必须有更好的解决方案,因为有一些应用程序将 sso 与官方 facebook 应用程序一起使用。

关于android - 当在设备/模拟器上安装 Facebook 应用程序时,发布到用户 Facebook 墙无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5960224/

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