返回介绍

Ionic4 Facebook 插件

发布于 2019-11-23 07:40:58 字数 5150 浏览 1080 评论 0 收藏 0

Use the Facebook Connect plugin to obtain access to the native FB application on iOS and Android.

Requires Cordova plugin: cordova-plugin-facebook4 . For more info, please see the Facebook Connect .

安装 Installation

To use the FB plugin, you first have to create a new Facebook App inside of the Facebook developer portal at https://developers.facebook.com/apps .

fb-getstarted-1

Retrieve the App ID and App Name .

fb-getstarted-2

Then type in the following command in your Terminal, where APP_ID and APP_NAME are the values from the Facebook Developer portal.

 ionic cordova plugin add cordova-plugin-facebook4 --variable APP_ID="123456789" --variable APP_NAME="myApplication"

After, you'll need to add the native platforms you'll be using to your app in the Facebook Developer portal under your app's Settings:

fb-getstarted-3

Click 'Add Platform' .

fb-getstarted-4

At this point you'll need to open your project's config.xml file, found in the root directory of your project.

Take note of the id for the next step:

<widget version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">

You can also edit the id to whatever you'd like it to be.

iOS Install

Under 'Bundle ID', add the id from your config.xml file:

fb-getstarted-5

Android Install

Under 'Google Play Package Name', add the id from your config.xml file:

fb-getstarted-6

And that's it! You can now make calls to Facebook using the plugin.

Events

App events allow you to understand the makeup of users engaging with your app, measure the performance of your Facebook mobile app ads, and reach specific sets of your users with Facebook mobile app ads.

Activation events are automatically tracked for you in the plugin.

Events are listed on the insights page .

For tracking events, see logEvent and logPurchase .

https://github.com/jeduan/cordova-plugin-facebook4

安装 Installation

ionic cordova plugin add cordova-plugin-facebook4 npm install @ionic-native/facebook 
Ionic EE comes with fully supported and maintained plugins from the Ionic Team. Learn More or Contact Us
ionic enterprise register --key=YOURPRODUCTKEY npm install @ionic-enterprise/facebook 

支持的平台 Supported Platforms

  • Android
  • iOS
  • Browser

用法 Usage

import { Facebook, FacebookLoginResponse } from '@ionic-native/facebook/ngx';
constructor(private fb: Facebook) { }
...
this.fb.login(['public_profile', 'user_friends', 'email'])
  .then((res: FacebookLoginResponse) => console.log('Logged into Facebook!', res))
  .catch(e => console.log('Error logging into Facebook', e)); this.fb.logEvent(this.fb.EVENTS.EVENT_NAME_ADDED_TO_CART);

项目地址: https://github.com/jeduan/cordova-plugin-facebook4

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文