简体   繁体   English

Facebook for Android 3.0登录

[英]Facebook for Android 3.0 log in

I went through the tutorial and successfully implemented the log in and log out flow. 我完成了本教程,并成功实现了登录和注销流程。 However this works with the built-in login button: 但是,这可以与内置的登录按钮一起使用:

  <com.facebook.widget.LoginButton
        android:id="@+id/authButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="30dp"
        />

When the user selects eg. 当用户选择例如 an item from a list, a custom dialog appears with a Share option. 列表中的一个项目,将显示一个带有“共享”选项的自定义对话框。 When the user selects this Share option, I want to log in them to facebook and the usual stuff like ABC would like to access your profile, ABC would like to post to your friends etc. 当用户选择此“共享”选项时,我想将其登录到Facebook,而ABC之类的常用内容想访问您的个人资料,ABC想要发布给您的朋友等。

Edit: I guess I have found what I need , but I ran into a problem early. 编辑:我想我已经找到了我需要的东西 ,但是我早就遇到了问题。 I cannot import FacebookDialog . 我无法导入FacebookDialog Neither is it offered to me, nor can I use when I import com.facebook.*; 它既不提供给我,也不能在导入com.facebook.*;

According to this FacebookDialog is in the com.facebook.widget package. 根据 FacebookDialogcom.facebook.widget包。 However when I type import com.facebook.widget . 但是,当我输入import com.facebook.widget the only dialog that is offered is the WebDialog . 唯一提供的对话框是WebDialog

What I needed was the Feed dialog . 我需要的是“ 提要”对话框

Example: 例:

private void publishFeedDialog() {
    Bundle params = new Bundle();
    params.putString("name", "New level!");
    params.putString("description", "I have reached level " + lvel!");
    params.putString("link", "https://play.google.com/store/apps/details?id=com.myapp");
    params.putString("picture", "http://myapp.com/Images/icoon.png");

        WebDialog feedDialog = (
                new WebDialog.FeedDialogBuilder(this,
                    Session.getActiveSession(),
                    params))
                .setOnCompleteListener(new OnCompleteListener() {

                    @Override
                    public void onComplete(Bundle values,
                        FacebookException error) {
                         if (error == null) {
                                // When the story is posted, echo the success
                                // and the post Id.
                                final String postId = values.getString("post_id");
                                if (postId != null) {
                                    //Toast.makeText(getActivity(), "Posted story, id: "+postId, Toast.LENGTH_SHORT).show();
                                } else {
                                    // User clicked the Cancel button
                                    //Toast.makeText(getActivity().getApplicationContext(), "Publish cancelled", Toast.LENGTH_SHORT).show();
                                }
                            } else if (error instanceof FacebookOperationCanceledException) {
                                // User clicked the "x" button
                                //Toast.makeText(getActivity().getApplicationContext(), "Publish cancelled", Toast.LENGTH_SHORT).show();
                            } else {
                                // Generic, ex: network error
                                Toast.makeText(getApplicationContext(), 
                                    "Error sharing app",  Toast.LENGTH_SHORT).show();
                            }
                    }

                })
                .build();
            feedDialog.show();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM