-
-
Save onmyway133/f142311025735a5001dc67a135effc09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import FBSDK from 'react-native-fbsdk' | |
const { LoginButton, AccessToken, GraphRequest, GraphRequestManager } = FBSDK | |
class FacebookService { | |
constructor() { | |
this.requestManager = new GraphRequestManager() | |
} | |
makeLoginButton(callback) { | |
return ( | |
<LoginButton | |
readPermissions={["public_profile"]} | |
onLoginFinished={(error, result) => { | |
if (error) { | |
} else if (result.isCancelled) { | |
} else { | |
AccessToken.getCurrentAccessToken() | |
.then((data) => { | |
callback(data.accessToken) | |
}) | |
.catch(error => { | |
console.log(error) | |
}) | |
} | |
}} /> | |
) | |
} | |
makeLogoutButton(callback) { | |
return ( | |
<LoginButton onLogoutFinished={() => { | |
callback() | |
}} /> | |
) | |
} | |
async fetchProfile(callback) { | |
return new Promise((resolve, reject) => { | |
const request = new GraphRequest( | |
'/me', | |
null, | |
(error, result) => { | |
if (result) { | |
const profile = result | |
profile.avatar = `https://graph.facebook.com/${result.id}/picture` | |
resolve(profile) | |
} else { | |
reject(error) | |
} | |
} | |
) | |
this.requestManager.addRequest(request).start() | |
}) | |
} | |
} | |
export const facebookService = new FacebookService() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@onmyway133 this is fantastically useful to me right now but I think this callback argument is unnecessary: https://gist.github.com/onmyway133/f142311025735a5001dc67a135effc09#file-a-js-L41