This repository has been archived by the owner on Aug 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 349
Connect smart device
Roman Kushnarenko edited this page Jun 27, 2015
·
4 revisions
Recently facebook released new feature to support user authorization from Smart devices. Smart TV, for example.
The doc: https://developers.facebook.com/docs/facebook-login/for-devices
-
Enable
Login from Devices
inOAuth Settings
pane from app settings dashboard. -
Connect Device
Here, we don't need to login or anything with this lib. We can just call for this method. Just set a permissions (scope), that user that is connected via the device will need.
Permission[] permissions = new Permission[] { Permission.PUBLIC_PROFILE, }; SimpleFacebook.getInstance().connectDevice(permissions, new OnConnectDeviceListener() { @Override public void onComplete(Device device) { // this is the code, that user should use in next step String userCode = device.getUserCode(); // this is internal code for us to check if user made the next step String authorizationCode = device.getAuthorizationCode(); } });
-
Now, user should take the
userCode
from previous step and put manually in https://www.facebook.com/device -
Poll periodically with intervals of min 5 seconds to get Access Token.
Use
authorizationCode
from step (2)SimpleFacebook.getInstance().pollDeviceAuthorization(authorizationCode, new OnAuthorizationDeviceListener() { @Override public void onComplete(String accessToken) { // boom!, you have real access token } @Override public void onException(Throwable throwable) { String errorMessage = throwable.getMessage(); // this error message means something } });
#### Error messages that can be retrieved from polling
Error message | Description
--------------|------------
authorization_pending | User has not yet authorized your application. Continue polling at the rate specified in the response (device)
authorization_declined | User has declined to authorize your application. Your device should stop polling, cancel out of the Login flow and send the user back to the initial screen.
slow_down | Your device is polling too frequently. Slow down the polling to the interval specified in the first API call.
code_expired | The device code has expired. Cancel the Device Login flow and send the user back to the initial screen.
-
Setup
-
Login/Logout
-
Publish
-
Requests/Invite
-
Get
-
Additional options 🔻
-
Samples