mazllia / Social-Networking-Notes

NCTU CS Project (2012 Fall-2013 Spring)
0 stars 0 forks source link

Connect to Facebook #5

Closed mazllia closed 10 years ago

mazllia commented 10 years ago

Let our Model works with Facebook

mazllia commented 10 years ago

Apple Frameworks

Apple's Accounts.framework only provides sweet authentication. User's profile can be accessed with permission in this framework.

Apple's Social.framework encapsulates the request with SLRequest, use it to access Facebook's Web APIs (we may use Graph API, a JSON-return API here) to access information. With Facebook Login (aka. authentication), you access more information.

Facebook Graph API Getting Start

Graph API: Getting started provides absolutely clear and fantastic introduction about their Graph idea and developer tools.

http://graph.facebook.com is the API address. You can access http://graph.facebook.com/userName or http://graph.facebook.com/userID to get their public information (dependent on their privacy setting).

With Facebook Login (aka. authentication), you are able to access http://graph.facebook.com/me and http://graph.facebook.com/app with convenience. http://graph.facebook.com/me/friends returns all your friends in JSON array; you request more permission to get further information. See your permission the user give you by visiting http://graph.facebook.com/me/permission.

mazllia commented 10 years ago

Facebook SDK for iOS Login

Login checklist

  1. iOS and Android apps should use the native Login dialog that comes with our SDKs instead of custom web views
  2. Use a clearly branded "Log in with Facebook" button
  3. Ask only for the permissions that you need
  4. If people cancel the Login dialog for either read or publish permissions, do not display it again immediately
  5. Test your Login flow to make sure that there are no crashes or errors
  6. Provide a visible logout mechanism

Login sequence

The Facebook SDK automatically selects the optimal login dialog flow based on the account settings and capabilities of a person's device. This is the default sequence, which can be inserted/deleted the sequence by FBSession, that the Facebook SDK implements:

Permission

Initiate Facebook Login by calling open* methods on the FBSession class or by using the FBLoginView or FBUserSettingsViewController classes.

You should at least specify _basicinfo in readPermission in the first login.

Permissions

Read permissions include:

Publish permissions include:

mazllia commented 10 years ago

IDE Problem

If you use FB SDK classes in Interface Builder, you have to specify the linker option -ObjC to prevent possible linking error.

To use FBLoginView in standard login sequence (to include safari), specify the following in plist:

URL types:[
    Item 0:{
        URL Schemes:[
            Item 0: fb174186899453258
        ]
    }
]

<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fb174186899453258</string>
        </array>
    </dict>
</array>
mazllia commented 10 years ago

FBRequestConnection

We use FBRequestConnection, which use the single FBRequest, to use FB Graph API (or Open Graph API). In its completion block, you get an FBGraphObject.

FBGraphObject

FBGraphObject is a subclass of NSMutableDictionary. When you access the token, you get FBGraphArray, which is a subclass of NSMutableArray. FB SDK has parsed the JSON for you.

for (NSDictionary<FBGraphUser> *userDictionary in result[@"tokenName"])