投递到用户的Facebook墙上时,Facebook的应用程序安装在设备/仿真器不工作 [英] Post to user facebook wall not working when Facebook app is installed on device/emulator

查看:114
本文介绍了投递到用户的Facebook墙上时,Facebook的应用程序安装在设备/仿真器不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立的一个使用<一个活动href="http://stackoverflow.com/questions/2953146/android-java-post-simple-text-to-facebook-wall">this执行(见接受的答案)发布在用户的Facebook墙上的状态更新。

I've built an activity that uses this implementation (see the accepted answer) to post a status update on a user's facebook wall.

它的工作原理没有问题,如果仿真器/手机没有安装Facebook应用程序。

It works with no problem if the emulator/phone does not have the facebook app installed.

如果仿真器/手机已经安装了Facebook应用程序,Facebook应用程序加载的登陆界面,而是试图登录后,Facebook的应用程序就这样消失带我回到我的应用程序。

If the emulator/phone has the facebook app installed, the facebook app loads the login screen, but after trying to login, the facebook app just disappears bringing me back to my app.

有没有人有安装Facebook应用程序时,这方面的经验?

Has anyone had this experience when the facebook app is installed?

我的code:

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的告诉我:

Logcat is telling me this:

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的实施工作的一台设备和不是另一个....

EDIT : After having to install the android development platform on multiple machines over the past year and ALWAYS having an issue with Facebook after creating the new development environments, I have found that this simple answer can be the cause for a Facebook implementation working on one device and not another....

秘密Facebook的API密钥(一个你在developer.facebook.com列表)将被每个版本您的应用程序,你打包用不同的证书不同。例如,假设你有两个开发机器。由于这两个机器将建立一个不同的证书应用程序,你必须确保你生成一个Facebook的API密钥对每一台机器,并列出它们在developer.facebook.com。

The secret Facebook API key (the one you list on developer.facebook.com) will be different for each version of your app that you package with a different certificate. For example, say you have two development machines. Since both of these machines will build your applications with a different certificates, you must ensure that you generate a Facebook API secret key for each machine and list them at developer.facebook.com.

推荐答案

这是因为当你登录的Facebook帐户,然后登录会话在设备中创建的。您可以从Facebook的做你的任务后注销。

It is because when you logged in the facebook account then your login session is created in the device. You have to logout from the facebook after doing your task.

这篇关于投递到用户的Facebook墙上时,Facebook的应用程序安装在设备/仿真器不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆