博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
facebook登录和分享
阅读量:4291 次
发布时间:2019-05-27

本文共 26037 字,大约阅读时间需要 86 分钟。

          整体来说,Facebook在国际化中做的是非常好的。也是,Twitter和YouTube都是Google自己家的,在中国政府受挫之后,就不方便投入太多,怎么做都好像一个血脉,一个味道。

          然后Facebook就不一样,小札的丈母娘祖上就是中国的,而且小札年轻,特别喜欢和挑战新的事务。。据说,Facebook为了在非洲的使用体验,专门派工程师到非常调研,非常到位的。

 

Facebook 的开发者支持分成两块:

        账户登录 Account login,和 Account Kit 。

提供的这两个服务,都提供了各种平台的支持,ios,andorid,web,mobilePhone等等。

 

Account Kit 提供电话号码和邮箱登录功能,无需玩家记忆任何其他密码。

“Facebook 登录”让玩家能够使用他们现有的 Facebook 帐户两步轻松完成帐户注册。

两者结合使用,效果更好 — 可用于壮大您的客户群。

2018 年 8 月之前,Account Kit 不会收取任何短信费用,之后会按照标准的短信费率,对每月确认短信数量超出 10 万的应用收费。

 

应该说,这两个功能属于异曲同工的作用,具体的使用可以参考产品和业务的需要进行选型,。。在开发的时候,可以同时继承和包装,需要的时候,直接使用。

 

AndroidSDK文档:

客户端SDK_android下载:

一,用户登录

好了,下面开始进行具体的步骤了::

    1,跟所有的三方账户一样,注册开发者账户,创建应用,获得应用编号口令什么的。

    2,gradle配置

repositories {  jcenter()}dependencies {  compile 'com.facebook.android:account-kit-sdk:4.+'}{  jcenter()}dependencies {  compile 'com.facebook.android:account-kit-sdk:4.+'}

    3,配置manifest

android:name="com.facebook.accountkit.ApplicationName" android:value="@string/app_name" />

    根据应用的情况,可能需要更多的配置,允许AccountKitActivity的启动,

android:name="com.facebook.accountkit.ui.AccountKitActivity" android:theme="@style/AppLoginTheme" tools:replace="android:theme" />

    4*,如果想禁用应用内事件,可以加入。。这里默认的value是true。。这里的应用内事件表示 AccountKit 登录展示 ,AccountKit登录开始,AccountKit登录尝试,AccountKit的登录。这里的统计可以在控制面板的漏斗里面看到。

android:name="com.facebook.accountkit.FacebookAppEventsEnabled" android:value="false"/>

    5,检查当前会话,意思就是登录之后的回调类似于。当在开发者的控制面板里启用客户端的访问口令流程,登录状态就会传给客户端程序。

 

import com.facebook.accountkit.AccountKit;import com.facebook.accountkit.AccessToken;AccessToken accessToken = AccountKit.getCurrentAccessToken();if (accessToken != null) {  //Handle Returning User} else {  //Handle new or logged out user} com.facebook.accountkit.AccountKit;import com.facebook.accountkit.AccessToken;AccessToken accessToken = AccountKit.getCurrentAccessToken();if (accessToken != null) {  //Handle Returning User} else {  //Handle new or logged out user}

    6,短信登录流程。

 

import com.facebook.accountkit.AccountKit;public static int APP_REQUEST_CODE = 99;public void phoneLogin(final View view) {  final Intent intent = new Intent(getActivity(), AccountKitActivity.class);  AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder =    new AccountKitConfiguration.AccountKitConfigurationBuilder(      LoginType.PHONE,      AccountKitActivity.ResponseType.CODE); // or .ResponseType.TOKEN  // ... perform additional configuration ...  intent.putExtra(    AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION,    configurationBuilder.build());  startActivityForResult(intent, APP_REQUEST_CODE);} com.facebook.accountkit.AccountKit;public static int APP_REQUEST_CODE = 99;public void phoneLogin(final View view) {  final Intent intent = new Intent(getActivity(), AccountKitActivity.class);  AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder =    new AccountKitConfiguration.AccountKitConfigurationBuilder(      LoginType.PHONE,      AccountKitActivity.ResponseType.CODE); // or .ResponseType.TOKEN  // ... perform additional configuration ...  intent.putExtra(    AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION,    configurationBuilder.build());  startActivityForResult(intent, APP_REQUEST_CODE);}

        APP_REQUEST_CODE 是您用于追踪登录流程的自定义代码。它可以是任何整数,但需要由您的应用程序设置。

        初始化 intent(意图)附加程序时,请务必指定与 Facebook 开发者门户网站面板中的应用授权设置相匹配的 AccountKitActivity.ResponseType:如果您的应用面板的启用客户端访问口令流程开关设置为“开”,则指定为TOKEN,如果设置为“关”,则指定为 CODE。

     7,邮箱登录流程

import com.facebook.accountkit.AccountKit;public static int APP_REQUEST_CODE = 99;public void emailLogin(final View view) {  final Intent intent = new Intent(getActivity(), AccountKitActivity.class);  AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder =    new AccountKitConfiguration.AccountKitConfigurationBuilder(      LoginType.EMAIL,      AccountKitActivity.ResponseType.CODE); // or .ResponseType.TOKEN  // ... perform additional configuration ...  intent.putExtra(    AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION,    configurationBuilder.build());  startActivityForResult(intent, APP_REQUEST_CODE);} com.facebook.accountkit.AccountKit;public static int APP_REQUEST_CODE = 99;public void emailLogin(final View view) {  final Intent intent = new Intent(getActivity(), AccountKitActivity.class);  AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder =    new AccountKitConfiguration.AccountKitConfigurationBuilder(      LoginType.EMAIL,      AccountKitActivity.ResponseType.CODE); // or .ResponseType.TOKEN  // ... perform additional configuration ...  intent.putExtra(    AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION,    configurationBuilder.build());  startActivityForResult(intent, APP_REQUEST_CODE);}

点击邮件的地址回到应用,需要一个中间者进行重定向。

android:name="com.facebook.accountkit.ui.AccountKitEmailRedirectActivity">
// if your Facebook App ID is 1234567, you should use ak1234567
akFACEBOOK_APP_ID
akFACEBOOK_APP_ID

API的其他功能:
       AccountKitConfigurationBuilder 对象通过提供允许您在运行时改写默认属性的方法。
       setInitialAuthState(String initialAuthState)           (可选)由开发者生成的一个随机数,用于确认收到的响应与请求匹配。
        setInitialEmail(String initialEmail)        (可选)在邮箱登录流程中预填充用户的电子邮箱。
        setDefaultCountryCode(String defaultCountryCode)          (可选)设置短信登录流程中默认显示的国家/地区代码。
        setInitialPhoneNumber(PhoneNumber initialPhoneNumber)             (可选)在短信登录流程中预填充用户的手机号码。
        setFacebookNotificationsEnabled(boolean facebookNotificationsEnabled)       (可选)如果设置此标记,Account Kit 就会向用户提供在短信发送失败后,通过 Facebook 通知接收验证消息的选项,前提是他们的手机号码与 Facebook 帐户关联。关联的手机号码必须是 Facebook 帐户的主要手机号码。
默认:true
         setReadPhoneStateEnabled(boolean readPhoneStateEnabled);
         setReceiveSMS(boolean receiveSMSEnabled);
         setSMSWhitelist(String[] smsWhitelist);
         setSMSBlacklist(String[] smsBlacklist);

 

 

下面一大块,是自定制Android UI部分的:

开发者SDK:

    基本UI:

           经典:

          半透明:

          现代:

    高级UI:

为应用添加皮肤:

// constructor without a background imageAccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder;UIManager uiManager;// Skin is CLASSIC, CONTEMPORARY, or TRANSLUCENTuiManager = new SkinManager(            Skin 
, @ColorInt int
);configurationBuilder.setUIManager(uiManager);AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder;UIManager uiManager;// Skin is CLASSIC, CONTEMPORARY, or TRANSLUCENTuiManager = new SkinManager( Skin
, @ColorInt int
);configurationBuilder.setUIManager(uiManager);
// constructor with a background image imageAccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder;UIManager uiManager;// Skin is CLASSIC, CONTEMPORARY, or TRANSLUCENT// Tint is WHITE or BLACK// TintIntensity is a value between 55-85%uiManager = new SkinManager(            Skin 
, @ColorInt int
, @DrawableRes int
, Tint
, double
);configurationBuilder.setUIManager(uiManager);UIManager uiManager;// Skin is CLASSIC, CONTEMPORARY, or TRANSLUCENT// Tint is WHITE or BLACK// TintIntensity is a value between 55-85%uiManager = new SkinManager( Skin
, @ColorInt int
, @DrawableRes int
, Tint
, double
);configurationBuilder.setUIManager(uiManager);

高级UI部分:

public class MyAdvancedUIManager extends BaseUIManager {    private final ButtonType confirmButton;    private final ButtonType entryButton;    private final TextPosition textPosition;    public MyAdvancedUIManager(            final ButtonType confirmButton,            final ButtonType entryButton,            final LoginType loginType,            final TextPosition textPosition,            final int themeResourceId) {        super(loginType, themeResourceId);        this.confirmButton = confirmButton;        this.entryButton = entryButton;        this.textPosition = textPosition;    }    private MyAdvancedUIManager(final Parcel source) {        super(source);        String s = source.readString();        final ButtonType confirmButton = s == null ? null : ButtonType.valueOf(s);        s = source.readString();        final ButtonType entryButton = s == null ? null : ButtonType.valueOf(s);        s = source.readString();        final TextPosition textPosition = s == null ? null : TextPosition.valueOf(s);        this.confirmButton = confirmButton;        this.entryButton = entryButton;        this.textPosition = textPosition;    }    @Override    @Nullable    public Fragment getHeaderFragment(final LoginFlowState state) {        Fragment headerFragment;        switch (state) {            case PHONE_NUMBER_INPUT:            case EMAIL_INPUT:            case EMAIL_VERIFY:            case SENDING_CODE:            case SENT_CODE:            case CODE_INPUT:            case VERIFYING_CODE:            case VERIFIED:            case ACCOUNT_VERIFIED:            case CONFIRM_ACCOUNT_VERIFIED:            case CONFIRM_INSTANT_VERIFICATION_LOGIN:                // insert appropriate customizations for headerFragment            case ERROR:                // handle appropriate error for headerFragment            default:                headerFragment = new Fragment();        }        return headerFragment;    }    public @Nullable ButtonType getButtonType(final LoginFlowState state) {        switch (state) {            case PHONE_NUMBER_INPUT:                return entryButton;            case EMAIL_INPUT:                return entryButton;            case CODE_INPUT:                return confirmButton;            default:                return null;        }    }    @Override    public void onError(final AccountKitError error) {        // handle error    }    @Override    public void writeToParcel(final Parcel dest, final int flags) {        super.writeToParcel(dest, flags);        dest.writeString(confirmButton != null ? confirmButton.name() : null);        dest.writeString(entryButton != null ? entryButton.name() : null);        dest.writeString(textPosition != null ? textPosition.name() : null);    }    public static final Creator
CREATOR = new Creator
() { @Override public MyAdvancedUIManager createFromParcel(final Parcel source) { return new MyAdvancedUIManager(source); } @Override public MyAdvancedUIManager[] newArray(final int size) { return new MyAdvancedUIManager[size]; } };} class MyAdvancedUIManager extends BaseUIManager { private final ButtonType confirmButton; private final ButtonType entryButton; private final TextPosition textPosition; public MyAdvancedUIManager( final ButtonType confirmButton, final ButtonType entryButton, final LoginType loginType, final TextPosition textPosition, final int themeResourceId) { super(loginType, themeResourceId); this.confirmButton = confirmButton; this.entryButton = entryButton; this.textPosition = textPosition; } private MyAdvancedUIManager(final Parcel source) { super(source); String s = source.readString(); final ButtonType confirmButton = s == null ? null : ButtonType.valueOf(s); s = source.readString(); final ButtonType entryButton = s == null ? null : ButtonType.valueOf(s); s = source.readString(); final TextPosition textPosition = s == null ? null : TextPosition.valueOf(s); this.confirmButton = confirmButton; this.entryButton = entryButton; this.textPosition = textPosition; } @Override @Nullable public Fragment getHeaderFragment(final LoginFlowState state) { Fragment headerFragment; switch (state) { case PHONE_NUMBER_INPUT: case EMAIL_INPUT: case EMAIL_VERIFY: case SENDING_CODE: case SENT_CODE: case CODE_INPUT: case VERIFYING_CODE: case VERIFIED: case ACCOUNT_VERIFIED: case CONFIRM_ACCOUNT_VERIFIED: case CONFIRM_INSTANT_VERIFICATION_LOGIN: // insert appropriate customizations for headerFragment case ERROR: // handle appropriate error for headerFragment default: headerFragment = new Fragment(); } return headerFragment; } public @Nullable ButtonType getButtonType(final LoginFlowState state) { switch (state) { case PHONE_NUMBER_INPUT: return entryButton; case EMAIL_INPUT: return entryButton; case CODE_INPUT: return confirmButton; default: return null; } } @Override public void onError(final AccountKitError error) { // handle error } @Override public void writeToParcel(final Parcel dest, final int flags) { super.writeToParcel(dest, flags); dest.writeString(confirmButton != null ? confirmButton.name() : null); dest.writeString(entryButton != null ? entryButton.name() : null); dest.writeString(textPosition != null ? textPosition.name() : null); } public static final Creator
CREATOR = new Creator
() { @Override public MyAdvancedUIManager createFromParcel(final Parcel source) { return new MyAdvancedUIManager(source); } @Override public MyAdvancedUIManager[] newArray(final int size) { return new MyAdvancedUIManager[size]; } };}
public class CustomAdvancedUIManager extends BaseUIManager {    /*implementation here */}UIManager advancedUIManager = new CustomAdvancedUIManager(loginType, themeId, ...);configuration.setUIManager(advancedUIManager)UIManager themeManager = new ThemeUIManager(loginType, themeId);configuration.setUIManager(themeManager); class CustomAdvancedUIManager extends BaseUIManager {    /*implementation here */}UIManager advancedUIManager = new CustomAdvancedUIManager(loginType, themeId, ...);configuration.setUIManager(advancedUIManager)UIManager themeManager = new ThemeUIManager(loginType, themeId);configuration.setUIManager(themeManager);

Android偏好设置的API:

最多可以为每位用户存储 100 个键/值对。键是 100 个字符以内的字符串,可以包含大小写字母、数字和下划线等字符。值是 1000 个字符以内的字符串。

// Load all preferences for this account:    AccountKit.getAccountPreferences().loadPreferences(new PrefsLoadListener());    // Load a specific preference:    AccountKit.getAccountPreferences().loadPreference("nickname", new SinglePrefLoadListener());    // Set a preference:    AccountKit.getAccountPreferences().setPreference("favoritecolor", "3b5998", new PrefSetListener());    // Delete a preference:    AccountKit.getAccountPreferences().loadPreference("timesincelastlogin ", new PrefDeleteListener());    AccountKit.getAccountPreferences().loadPreferences(new PrefsLoadListener());    // Load a specific preference:    AccountKit.getAccountPreferences().loadPreference("nickname", new SinglePrefLoadListener());    // Set a preference:    AccountKit.getAccountPreferences().setPreference("favoritecolor", "3b5998", new PrefSetListener());    // Delete a preference:    AccountKit.getAccountPreferences().loadPreference("timesincelastlogin ", new PrefDeleteListener());
private class PrefsLoadListener implements AccountPreferences.OnLoadPreferencesListener {    public void onLoadPreferences(        @Nullable Map
preferences, @Nullable AccountKitError error) { if (error != null) { // ... handle error appropriately ... return; } // You now have access to all existing user preferences in a Map } } private class SinglePrefLoadListener implements AccountPreferences.OnLoadPreferenceListener { public void onLoadPreference(String key, @Nullable String value, @Nullable AccountKitError error) { if (error != null) { // ... handle error appropriately ... return; } // ... use the delivered value and key ... } } private class PrefSetListener implements AccountPreferences.OnSetPreferenceListener { public void onSetPreference(String key, String value, @Nullable AccountKitError error) { if (error != null) { // ... handle error appropriately ... return; } // ... use the delivered value and key ... } } private class PrefDeleteListener implements AccountPreferences.OnDeletePreferenceListener { public void onDeletePreference(String key, @Nullable AccountKitError error) { if (error != null) { // ... handle error appropriately ... return; } // You have been notified that the value associated with "key" was deleted } } class PrefsLoadListener implements AccountPreferences.OnLoadPreferencesListener { public void onLoadPreferences( @Nullable Map
preferences, @Nullable AccountKitError error) { if (error != null) { // ... handle error appropriately ... return; } // You now have access to all existing user preferences in a Map } } private class SinglePrefLoadListener implements AccountPreferences.OnLoadPreferenceListener { public void onLoadPreference(String key, @Nullable String value, @Nullable AccountKitError error) { if (error != null) { // ... handle error appropriately ... return; } // ... use the delivered value and key ... } } private class PrefSetListener implements AccountPreferences.OnSetPreferenceListener { public void onSetPreference(String key, String value, @Nullable AccountKitError error) { if (error != null) { // ... handle error appropriately ... return; } // ... use the delivered value and key ... } } private class PrefDeleteListener implements AccountPreferences.OnDeletePreferenceListener { public void onDeletePreference(String key, @Nullable AccountKitError error) { if (error != null) { // ... handle error appropriately ... return; } // You have been notified that the value associated with "key" was deleted } }

 

 

 

二,用户注册登录

最总访问口令:

 

@Overridepublic void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    callbackManager = CallbackManager.Factory.create();    accessTokenTracker = new AccessTokenTracker() {        @Override        protected void onCurrentAccessTokenChanged(            AccessToken oldAccessToken,            AccessToken currentAccessToken) {                // Set the access token using                 // currentAccessToken when it's loaded or set.        }    };    // If the access token is available already assign it.    accessToken = AccessToken.getCurrentAccessToken();}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {    super.onActivityResult(requestCode, resultCode, data);    callbackManager.onActivityResult(requestCode, resultCode, data);}@Overridepublic void onDestroy() {    super.onDestroy();    accessTokenTracker.stopTracking();}public void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    callbackManager = CallbackManager.Factory.create();    accessTokenTracker = new AccessTokenTracker() {        @Override        protected void onCurrentAccessTokenChanged(            AccessToken oldAccessToken,            AccessToken currentAccessToken) {                // Set the access token using                 // currentAccessToken when it's loaded or set.        }    };    // If the access token is available already assign it.    accessToken = AccessToken.getCurrentAccessToken();}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {    super.onActivityResult(requestCode, resultCode, data);    callbackManager.onActivityResult(requestCode, resultCode, data);}@Overridepublic void onDestroy() {    super.onDestroy();    accessTokenTracker.stopTracking();}

追踪当前个人资料:

 

 

@Overridepublic void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    callbackManager = CallbackManager.Factory.create();    profileTracker = new ProfileTracker() {        @Override        protected void onCurrentProfileChanged(                Profile oldProfile,                Profile currentProfile) {            // App code        }    };}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {    super.onActivityResult(requestCode, resultCode, data);    callbackManager.onActivityResult(requestCode, resultCode, data);}@Overridepublic void onDestroy() {    super.onDestroy();    profileTracker.stopTracking();}public void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    callbackManager = CallbackManager.Factory.create();    profileTracker = new ProfileTracker() {        @Override        protected void onCurrentProfileChanged(                Profile oldProfile,                Profile currentProfile) {            // App code        }    };}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {    super.onActivityResult(requestCode, resultCode, data);    callbackManager.onActivityResult(requestCode, resultCode, data);}@Overridepublic void onDestroy() {    super.onDestroy();    profileTracker.stopTracking();}

 

三,Facebook分享

Facebook的分享,有一个前提条件,就是应用必须已经安装,才能够分享。

链接的分享:ShareLinkContent模型进行。

      截至 2017 年 4 月 18 日,图谱 API 版本 2.9 及更高版本不再支持下列参数。对于版本 2.8 及更低版本,这些参数将继续有效,直到 2017 年 7 月 17 日。

          contentTitle,表示链接中的内容的标题,imageURL,将在帖子中显示的缩略图的网址,内容的 contentDescription,通常为 2-4 个句子

ShareLinkContent content = new ShareLinkContent.Builder()

        .setContentUrl(Uri.parse("https://developers.facebook.com"))
        .build();

照片分享:小于12MB,客户端在7.0以上,SharePhotoContent模型进行。

 

Bitmap image = ...SharePhoto photo = new SharePhoto.Builder()        .setBitmap(image)        .build();SharePhotoContent content = new SharePhotoContent.Builder()        .addPhoto(photo)        .build(); image = ...SharePhoto photo = new SharePhoto.Builder()        .setBitmap(image)        .build();SharePhotoContent content = new SharePhotoContent.Builder()        .addPhoto(photo)        .build();

 

视频分享:小于12MB,ShareVideoContent模型进行

 

Uri videoFileUri = ...ShareVideo = new ShareVideo.Builder()        .setLocalUrl(videoUrl)        .build();ShareVideoContent content = new ShareVideoContent.Builder()        .setVideo(video)        .build(); videoFileUri = ...ShareVideo = new ShareVideo.Builder()        .setLocalUrl(videoUrl)        .build();ShareVideoContent content = new ShareVideoContent.Builder()        .setVideo(video)        .build();

多媒体分享:

 

用户需要安装版本 71 或以上的原生 Android 版 Facebook 应用。

照片大小必须小于 12MB。
视频大小必须小于 12MB。
用户每次可以分享最多包含 6 个照片和视频元素的内容。

 

SharePhoto sharePhoto1 = new SharePhoto.Builder()    .setBitmap(...)    .build();SharePhoto sharePhoto2 = new SharePhoto.Builder()    .setBitmap(...)    .build();ShareVideo shareVideo1 = new ShareVideo.Builder()    .setLocalUrl(...)    .build();ShareVideo shareVideo2 = new ShareVideo.Builder()    .setLocalUrl(...)    .build();ShareContent shareContent = new ShareMediaContent.Builder()    .addMedium(sharePhoto1)    .addMedium(sharePhoto2)    .addMedium(shareVideo1)    .addMedium(shareVideo2)    .build();ShareDialog shareDialog = new ShareDialog(...);shareDialog.show(shareContent, Mode.AUTOMATIC); sharePhoto1 = new SharePhoto.Builder()    .setBitmap(...)    .build();SharePhoto sharePhoto2 = new SharePhoto.Builder()    .setBitmap(...)    .build();ShareVideo shareVideo1 = new ShareVideo.Builder()    .setLocalUrl(...)    .build();ShareVideo shareVideo2 = new ShareVideo.Builder()    .setLocalUrl(...)    .build();ShareContent shareContent = new ShareMediaContent.Builder()    .addMedium(sharePhoto1)    .addMedium(sharePhoto2)    .addMedium(shareVideo1)    .addMedium(shareVideo2)    .build();ShareDialog shareDialog = new ShareDialog(...);shareDialog.show(shareContent, Mode.AUTOMATIC);

“赞”按钮

“赞”按钮是用户与好友分享内容的快捷途径。轻触“赞”按钮即可为应用中的内容点“赞”,并将内容分享到 Facebook。

 

 

LikeView likeView = (LikeView) findViewById(R.id.like_view);likeView.setObjectIdAndType(    "https://www.facebook.com/FacebookDevelopers",    LikeView.ObjectType.PAGE); likeView = (LikeView) findViewById(R.id.like_view);likeView.setObjectIdAndType(    "https://www.facebook.com/FacebookDevelopers",    LikeView.ObjectType.PAGE);

 

 

 

“分享”按钮

“分享”按钮将调用分享对话框。要添加“分享”按钮

 

ShareButton shareButton = (ShareButton)findViewById(R.id.fb_share_button);shareButton.setShareContent(content); shareButton = (ShareButton)findViewById(R.id.fb_share_button);shareButton.setShareContent(content);

分享对话框

分享对话框会切换到原生 Android 版 Facebook 应用,并在发布帖子后将控制权交还您的应用。如果未安装 Facebook 应用,会自动回退到网页对话框。

 

 

callbackManager = CallbackManager.Factory.create();        shareDialog = new ShareDialog(this);        // this part is optional        shareDialog.registerCallback(callbackManager, new FacebookCallback
() { ... });= CallbackManager.Factory.create(); shareDialog = new ShareDialog(this); // this part is optional shareDialog.registerCallback(callbackManager, new FacebookCallback
() { ... });
if (ShareDialog.canShow(ShareLinkContent.class)) {    ShareLinkContent linkContent = new ShareLinkContent.Builder()            .setContentUrl(Uri.parse("http://developers.facebook.com/android"))            .build();    shareDialog.show(linkContent);} (ShareDialog.canShow(ShareLinkContent.class)) {    ShareLinkContent linkContent = new ShareLinkContent.Builder()            .setContentUrl(Uri.parse("http://developers.facebook.com/android"))            .build();    shareDialog.show(linkContent);}
@Overrideprotected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {    super.onActivityResult(requestCode, resultCode, data);    callbackManager.onActivityResult(requestCode, resultCode, data);}protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {    super.onActivityResult(requestCode, resultCode, data);    callbackManager.onActivityResult(requestCode, resultCode, data);}

 

话题标签:

英文分享:

自定义界面:

分享链接:

另外Facebook 同时也提供了分享,推送,Messager(基于Webhook),社交,邀请,广告,应用分析等开发者工具。

其他的也没什么说的,这里提供一下官方给的例子吧:

       

 

转载地址:http://qcegi.baihongyu.com/

你可能感兴趣的文章
nginx+redis+tomcat三级缓存架构讲解
查看>>
Reactor模式详解
查看>>
基于OpenRestry部署nginx+lua实现流量定向分发
查看>>
netty源码分析之-服务端启动核心源码分析(5)
查看>>
Storm并行度和流分组详解
查看>>
缓存数据预热详解
查看>>
热点数据降级详解(storm+nginx+lua)
查看>>
加载更多功能实现
查看>>
React相关Dom约束性和非约束性操作
查看>>
Hystrix高可用架构介绍
查看>>
netty源码分析之-SimpleChannelInboundHandler与ChannelInboundHandlerAdapter详解(6)
查看>>
netty源码分析之-开发过程中重要事项分析(7)
查看>>
Sublime Text3插件详解
查看>>
netty源码分析之-ByteBuf详解(8)
查看>>
javascript函数定义三种方式详解
查看>>
javascript中this关键字详解
查看>>
javascript关于call与apply方法详解
查看>>
netty源码分析之-ReferenceCounted详解(9)
查看>>
javascript闭包详解
查看>>
javascript类的创建与实例对象
查看>>