1 | # ngx-facebook
|
2 |
|
3 | # This package has been renamed to ngx-facebook
|
4 |
|
5 | This is a wrapper for the official Facebook JavaScript SDK. It makes it easier to use Facebook SDK with Angular 2+ by providing components, providers and types.
|
6 |
|
7 | <br><br>
|
8 |
|
9 | [![NPM](https://nodei.co/npm/ng2-facebook-sdk.png?stars&downloads)](https://nodei.co/npm/ng2-facebook-sdk/)
|
10 | [![NPM](https://nodei.co/npm-dl/ng2-facebook-sdk.png?months=6&height=2)](https://nodei.co/npm/ng2-facebook-sdk/)
|
11 |
|
12 | [![npm](https://img.shields.io/npm/l/express.svg)](https://www.npmjs.com/package/ngx-facebook)
|
13 | [![CircleCI](https://img.shields.io/circleci/project/github/zyra/ngx-facebook.svg)](https://circleci.com/gh/zyra/ngx-facebook)
|
14 | [![Sauce Test Status](https://saucelabs.com/buildstatus/ng2facebooksdk)](https://saucelabs.com/u/ng2facebooksdk)
|
15 |
|
16 | [![Sauce Test Status](https://saucelabs.com/browser-matrix/ng2facebooksdk.svg)](https://saucelabs.com/u/ng2facebooksdk)
|
17 |
|
18 | <br><br>
|
19 |
|
20 | ## Installation
|
21 |
|
22 | #### 1. Install via NPM:
|
23 |
|
24 | ```shell
|
25 | npm i --save ngx-facebook
|
26 | ```
|
27 |
|
28 | #### 2. Add the Facebook JavaScript SDK to your index.html
|
29 | ```html
|
30 | <script type="text/javascript" src="https://connect.facebook.net/en_US/sdk.js"></script>
|
31 | ```
|
32 |
|
33 | #### 3. Import `FacebookModule` into your app's root module
|
34 | ```typescript
|
35 |
|
36 | import { FacebookModule } from 'ngx-facebook';
|
37 |
|
38 | @NgModule({
|
39 | ...
|
40 | imports: [
|
41 | FacebookModule.forRoot()
|
42 | ],
|
43 | ...
|
44 | })
|
45 | export class AppModule { }
|
46 |
|
47 | ```
|
48 |
|
49 | If you only want to use [FacebookService](https://zyra.github.io/ngx-facebook/facebook-service) only, without using the other components, then you can import it in your app's module instead of `FacebookModule`.
|
50 |
|
51 | #### 4. Inject `FacebookService` and call the `init` method (optional):
|
52 | This method must be called before using [`login`](http://zyra.github.io/ngx-facebook/facebook-service/#login) or [`api`](http://zyra.github.io/ngx-facebook/facebook-service/#api) methods. It is not required for other methods/components.
|
53 |
|
54 | ```typescript
|
55 | import { FacebookService, InitParams } from 'ngx-facebook';
|
56 |
|
57 | ...
|
58 |
|
59 | export class MyComponentOrService {
|
60 |
|
61 | constructor(private fb: FacebookService) {
|
62 |
|
63 | let initParams: InitParams = {
|
64 | appId: '1234566778',
|
65 | xfbml: true,
|
66 | version: 'v2.8'
|
67 | };
|
68 |
|
69 | fb.init(initParams);
|
70 |
|
71 | }
|
72 |
|
73 | }
|
74 | ```
|
75 |
|
76 | <br><br><br><br>
|
77 |
|
78 | ## Documentation
|
79 | You can view complete and detailed documentation by visiting https://zyra.github.io/ngx-facebook/.
|
80 |
|
81 | <br><br><br><br>
|
82 |
|
83 | ## Example Usage
|
84 |
|
85 | You can view our [example project here](https://zyra.github.io/ngx-facebook-example/) and/or view its [source code here](https://github.com/zyra/ngx-facebook-example/)
|
86 |
|
87 | <br><br>
|
88 |
|
89 | ### Example of login with Facebook
|
90 |
|
91 | ```typescript
|
92 | import { FacebookService, LoginResponse } from 'ngx-facebook';
|
93 |
|
94 | @Component(...)
|
95 | export class MyComponent {
|
96 |
|
97 | constructor(private fb: FacebookService) { }
|
98 |
|
99 | loginWithFacebook(): void {
|
100 |
|
101 | this.fb.login()
|
102 | .then((response: LoginResponse) => console.log(response))
|
103 | .catch((error: any) => console.error(error));
|
104 |
|
105 | }
|
106 |
|
107 | }
|
108 | ```
|
109 |
|
110 | <br><br>
|
111 |
|
112 | ### Example of sharing on Facebook
|
113 | ```typescript
|
114 | import { FacebookService, UIParams, UIResponse } from 'ngx-facebook';
|
115 |
|
116 | ...
|
117 |
|
118 | share(url: string) {
|
119 |
|
120 | let params: UIParams = {
|
121 | href: 'https://github.com/zyra/ngx-facebook',
|
122 | method: 'share'
|
123 | };
|
124 |
|
125 | this.fb.ui(params)
|
126 | .then((res: UIResponse) => console.log(res))
|
127 | .catch((e: any) => console.error(e));
|
128 |
|
129 | }
|
130 | ```
|
131 |
|
132 | <br><br>
|
133 |
|
134 | ### Example of adding a Facebook like button
|
135 | ```html
|
136 | <fb-like href="https://github.com/zyra/ngx-facebook"></fb-like>
|
137 | ```
|
138 |
|
139 | <br><br>
|
140 |
|
141 | ### Example of playing a Facebook video
|
142 |
|
143 | #### Basic video component usage:
|
144 | ```html
|
145 | <fb-video href="https://www.facebook.com/facebook/videos/10153231379946729/"></fb-video>
|
146 | ```
|
147 |
|
148 | #### Advanced video component usage:
|
149 | ```html
|
150 | <fb-video href="https://www.facebook.com/facebook/videos/10153231379946729/" (paused)="onVideoPaused($event)"></fb-video>
|
151 | ```
|
152 | ```typescript
|
153 | import { Component, ViewChild } from '@angular/core';
|
154 | import { FBVideoComponent } from 'ngx-facebook';
|
155 |
|
156 | @Component(...)
|
157 | export class MyComponent {
|
158 |
|
159 | @ViewChild(FBVideoComponent) video: FBVideoComponent;
|
160 |
|
161 | ngAfterViewInit() {
|
162 | this.video.play();
|
163 | this.video.pause();
|
164 | this.video.getVolume();
|
165 | }
|
166 |
|
167 | onVideoPaused(ev: any) {
|
168 | console.log('User paused the video');
|
169 | }
|
170 |
|
171 | }
|
172 | ```
|
173 |
|
174 | <br><br><br><br>
|
175 |
|
176 | # Disclaimer
|
177 | A large portion of this module's documentation is copied from the official [Facebook Docs](https://developers.facebook.com/docs/). This is to make sure that everything is as clear as possible, and consistent with the way Facebook explains it.
|