zyra / ngx-facebook

Angular TypeScript Wrapper for Facebook SDK
http://zyra.github.io/ngx-facebook/
MIT License
209 stars 70 forks source link

Can you please post examples of how to use every method? #42

Closed laura2489 closed 7 years ago

laura2489 commented 7 years ago

I managed to log in an get the accessToken, but the api method doesn't seem to work or i don't know how to use it. Examples would be great. Thanks.

ihadeed commented 7 years ago

Hey @laura2489 ,

I do plan on improving the documentation and adding examples. But for now, is there a specific thing that you're trying to do that I can help out with?

Here is a quick example on how to use the api method:

class MyComponent {

  constructor(private fb: FacebookService){ .. }

  getMyProfile() {
    // must login before using `api`
    this.fb.api('/me')
      .then(res => console.log(res))
      .catch(error => console.error(error));
  }

}
laura2489 commented 7 years ago

Thank you for your prompt response. I tried that, and i keep getting the following error: "An active access token must be used to query information about the current user." If i provide the token, instead of /me, i get the following error: "(#803) Some of the aliases you requested do not exist: null"

ihadeed commented 7 years ago

@laura2489 you need to call the login method and successfully login before using the api method.

laura2489 commented 7 years ago

I did login and i managed to get the token using this.FB.getAuthResponse(). Do I have to set the token globally or something? {"accessToken":"EAAac7879mTwBAMevlLWBbZAHnshAr8w9VBQmE8cbBZCagi6utcMZAqoG3w8ZC5YdbWITT7M28dDJg8H7oGvshTWVNydGe2F0WkJZAvYmew6W9uuGdQWgPACwlTRdZAgRijK5NgeFoGxZB0OWGTx8n9An2uFCuz0WBLdmUAAI3ahjg2ZBlRaPtNFYZBLuShuU5KvYZD","userID":"........,"expiresIn":4639...."}

i saved it in localStorage.setItem('accessToken', ....); but still nothing :(

I should mention that i use Angular 2 with Webpack.

ihadeed commented 7 years ago

Please see the usage here: https://github.com/zyramedia/ng2-facebook-sdk-example

To use the api method, you need to call the login method first. You need to login the user every time they access your app. If they have already authorized your app, then the dialog will close immediately and the session will be restored.

laura2489 commented 7 years ago

Thank you very much. The example you posted helped me a lot. Now it works.

ihadeed commented 7 years ago

Glad to help!

alex-chaliy commented 6 years ago

How can I get user permissions for an app?

ihadeed commented 6 years ago

@alex-chaliy I think there's an end point like /<app-id>/permissions .. check their docs :)

Ruli-AlSe commented 6 years ago

@ihadeed thank you so much for your example, helped me a lot!!