Skip to content

Instantly share code, notes, and snippets.

@vladimir-ivanov
Created August 2, 2017 19:27
Show Gist options
  • Save vladimir-ivanov/a53641854fcf07483a346a96e235cd65 to your computer and use it in GitHub Desktop.
Save vladimir-ivanov/a53641854fcf07483a346a96e235cd65 to your computer and use it in GitHub Desktop.
facebook graph api sdk angular 2 / 4
import {Inject, Injectable, InjectionToken} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {AsyncSubject} from "rxjs/AsyncSubject";
export let FacebookSdk = new InjectionToken<any>("FacebookSdk");
@Injectable()
export class FbRequestService {
constructor(@Inject(FacebookSdk) private facebookSdk) {
}
request(path: string, params: any): Observable<any> {
const sub = new AsyncSubject();
this.facebookSdk.api(path, params, (response) => {
if (!response || response.error) {
sub.error(response.error || "Unspecified");
} else {
sub.next(response);
}
sub.complete();
});
return sub;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment