The Facebook SDK has been upgraded to 3.1.1. Recently, the latest SDK has been used to complete two basic functions: Login and posting in the project. These two functions already exist in the Facebook SDK, which is very simple to use. However, the difficulty in using the Facebook SDK is to understand the basis for building Facebook. In addition to the basic operations, I also want to talk about my current understanding (also from the official website documentation, but the understanding is not necessarily correct). However, we recommend that you go to the official website to check it out, after all, it is fundamental.
First, Facebook has two basic types: object and connection. Objects refer to Facebook's individual units such as people, pictures, and events. A connection is a connection between objects. People like this connection. We can find all the things that people like through the connection. Facebook makes all objects connected to social networks. This is the most basic concept of Facebook (I think ). Based on this social map (or social network), we can use graph path to access any information in this network, as long as you have access permissions. A person generally has many connections, such as feed (Real-Time Message), likes, and friends. We can access Real-Time Messages through "me/feed" or publish messages.
//session isn't open, so we have to open it if( ![[FBSession activeSession] isOpen] ) { //open session with write permission if( [FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"] defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { if( error ) { FACEBOOK_LOG(@"facebook---> openActiveSessionWithPublishPermissions() failed!!!!!!!!!!"); } else { FACEBOOK_LOG(@"facebook---> openActiveSessionWithPublishPermissions() successfully."); } //invokde delegate if( m_pDelegate ) { m_pDelegate->sessionStateChange( session, status, error ); } }] ) { FACEBOOK_LOG(@"facebook---> openActiveSessionWithPublishPermissions() return true."); } else { FACEBOOK_LOG(@"facebook---> openActiveSessionWithPublishPermissions() return false."); return false; } }
The Facebook reference in openactivesessionwithpublishpermissions () has been described in detail. However, allowloginui is very important. Generally, it is set to Yes, which means whether to bring up the login interface before the user logs in. Because the Facebook SDK retains the token, it is difficult to reproduce the login interface once you log on, because Facebook will use the token applied for the last time (the token is not attached to the program, and the program will be closed in time, the token is still stored ). Although the Facebook SDK contains closeandcleartoken (), this function does not always work (at least I call this function every time I close the program, but only a few prompts to bring up the login interface ).
Once you log in and have the write permission, you can send messages.
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: m_pstrLastMessage, @"message", @"http://www.yourweb.com", @"link", @"http://static.ak.fbcdn.net/rsrc.php/v2/y2/r/lpa-16iu9uw.gif", @"picture", @"China star", @"name", @"I love China", @"description", nil]; [FBRequestConnection startWithGraphPath:@"me/feed" parameters:params HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { if( error ) { FACEBOOK_LOG2( @"facebook---> message( \"%@\" ) posted failed!!!!!!!!!", m_pstrLastMessage ); } else { FACEBOOK_LOG2( @"facebook---> message( \"%@\" ) posted successfully.", m_pstrLastMessage ); } }];
A feed contains many attributes (including mandatory attributes such as strings or links, optional attribute images, and titles ). You can refer to the official website of the Facebook SDK in Graph API. The same connection corresponds to different property parameters, which can be viewed on the official website.
In these two aspects, we can implement the most common functions of Facebook. For more concepts, visit the official website. After three hours of reading, I have a headache. I cannot think of many Facebook concepts, especially the Internet. It takes a lot of effort to fully grasp the features. You can check the functions in the future!