How to get Facebook access token and User ID on iphone - iphone

I want to make a demo of using OAuth to get a facebook access token in a mobile app.
i have a button on the main view. After button is clicked, I use safari to open the facebook OAuth dialog. After logging in to facebook, I can't figure out how to get the access token and UserID.

You need to spend some time reading the documentation on how Facebook works with iOS. Specifically there is a whole documentation section dedication to iOS authentication.
The way you are currently doing it with redirecting to Safari is not the preferred way of handling this as far as I know.

Related

Firebase SSO Auth not working in Facebook In App Browser

We are using Firebase Auth and provide Google and Facebook login on our site.
We are a publisher and most of our stories are published as Instant Articles. However, some articles are locked and requires subscribers to login to read the full content.
This works in a normal browser, but when opening a non-IA link in FB In App Browser, the login popup appears but remains blank, and does not close.
Users are not signed in and can't login.
We are using:
firebase.auth().signInWithPopup(provider)
I was wondering if there are any ways besides the signInWithPopup that can help us achieve this?
Thx.
As #bojeil mentioned,
use firebase.auth().signInWithRedirect(provider) instead.

How to require user to login fb before accessing Facebook Canvas App webpapge directly?

I am new to Facebook App. I am developing my first Facebook Canvas App which links to a webpage hosting on my server.
I can now access the app by either:
(1) go to the Facebook App (http://apps.facebook.com/myappname), or
(2) directly access the webpage through URL(http://mywebsite.com/myapp).
I have set http://mywebsite.com/myapp as my canvas page in FB dashboard settings.
I want to avoid (2) by requiring user to login FB first before they can access the page. I would like to know how can I do that?
This may be a stupid question, but I have read the FB API documents (FB official guide talks a lot about setting custom login page) and searched through a lot of questions but they doesn't seem to fit what I need.
UPDATE:
I have tried something like putting the following in my webpage:
<script> top.location.href = 'http://apps.facebook.com/myappname'</script>
In this case, if user access the page by (1), there's no problem. If user access the page by (2), user will be redirected to Facebook.
However in the client side we can still view the content of the webpage even if user is not logging in to Facebook. I want to achieve this in the server side.
Thank you very much!
I have already solved the problem by using examples from Facebook PHP SDK version 3.
https://github.com/facebookarchive/facebook-php-sdk/blob/master/examples/example.php

C# Facebook sdk: posting on page on owner's behalf

I have a page on facebook and i want to get my page access token so that i could use it to post ob my page from a mobile application or web application using the facebook sdk for C#.
I think the whole idea would be:
user will go to my webpage.
user will then login to facebook.
user will be taken back to my page with the his page's access token.
i will save this access token and then use it to post on his page on his behalf.
Right now i am not sure whether these are the right steps or not and if i am right, how can i make a facebook login page where user can use?
EDIT:
I found some answer here: Programatically log in to facebook and post from server side
do i need to create a facebook app for that?

where am I supposed to use the OAuth Dialog?

on the facebook developers site it recommends using the OAuth Dialog where you use
https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_CANVAS_PAGE
replacing the the YOUR_APP_ID and YOUR_CANVAS_PAGE with what you have
my question is where am I supposed to put this?
do I put this somewhere on my index.php for my canvas page?
or aside from creating your app, do I need to make a website where info of my app should be displayed together with a link to my app using the OAuth Dialog?
You need to create website that will have the content of the app, since facebook will display it in the iframe.
As for the link you mentioned, it is used to get permissions (basic information, user's email etc). If you need that kind of information about the user, you have to redirect him there so he can grant the permission. If your app doesn't require any information about the user, you can just skip the authorization part.

Is it possible to post to Facebook without using Facebook Connect dialogs?

I would like to post updates to Facebook from my iPhone application. I know that there is a Facebook Connect project, but it requires displaying dialogs for entering user's credentials, dialog for posting content, etc. I would like to be able to get the credentials from application settings and post whatever the user put into UITextView.
Is it possible? or am I stack with Facebook Connect?
Thanks!
You need to use Facebook Connect to authenticate and let the user set privacy settings for your app on their profile. You might technically be able to write all the authentication code yourself (see Facebook's Developers page about authentication) but why bother when the experts have done it for you?
You can then use the Facebook Connect API to do whatever you need to do with Facebook, assuming the user has give your app permission to do so.