InProgramFacebook is often used to share apps and some interesting things. FB provides us with APIs, but in China, due to the large firewall, we cannot access the FB website normally, proxy and VPN are required.
Implementation Effect
The implementation process is as follows:
- Download the FB zip package for iOS, click, and decompress it.
- Double-click src/fbconnect. xcodeproj under the decompressed file and open it in xcode.
- Create a demo project for FB. My name is iPhone. Facebook. compile it correctly and run it.
- Copy the fbconnect folder from the fbconnect project to your new project.
- The most critical step is to configure the environment, find the src directory of the downloaded file package, and add it to the user header search path. For example:
Here, the download path is:/users/VSP/downloads/facebook-facebook-iphone-sdk-1059eb6/src
- Compile the program. It can be compiled normally without errors.
- Apply for your own development applications on the FB website :( http://www.facebook.com/developers)
- Add a button in the new project and define the corresponding click event.
Add:
# Import <uikit/uikit. h>
# Import "fbconnect/fbconnect. H"
# Import "fbconnect/fbsession. H"
# Define fb_app_key @ "your_app_key" // self-applied
# Define fb_sec_key @ "you_sec_key" // self-applied
@ Interface iphone_facebookviewcontroller : Uiviewcontroller {
Iboutlet Fbloginbutton * Fbbutton ;
Fbsession * Fbsession ;
ID < Fbrequestdelegate > Delegate ;
Int Status ;
}
-( Ibaction ) Clickbutton :( ID ) Sender ;
@ Property ( Nonatomic , Retain ) Fbsession * Fbsession ;
@ Property ( Nonatomic , Assign ) ID < Fbrequestdelegate > Delegate ;
@ End
Method:
# Import "iphone_facebookviewcontroller.h"
@ Implementation iphone_facebookviewcontroller
@ Synthesize fbsession ;
@ Synthesize Delegate ;
- ( Void ) Viewdidload {
[ Super Viewdidload ];
Status = 0 ;
If ( Self . Fbsession = Nil ) {
Self . Fbsession = [ Fbsession Sessionforapplication : Fb_app_key secret : Fb_sec_key Delegate : Self ];
}
}
- ( Void ) Session :( Fbsession *) Session didlogin :( Fbuid ) UID {
Status = 1 ;
Nsstring * Fql = [ Nsstring Stringwithformat : @ "Select uid, name from user where uid = % LLD" , Self . Fbsession . UID ];
Nsdictionary * Params = [ Nsdictionary Dictionarywithobject : Fql forkey : @ "Query" ];
[[ Fbrequest Requestwithdelegate : Self ] Call : @ "Facebook. fql. Query" Params : Params ];
}
- ( Void ) Request :( Fbrequest *) Request didload :( ID ) Result {
If ([ Request . Method isequaltostring : @ "Facebook. fql. Query" ]) {
Nsstring * Username = [ (( Nsdictionary *)[( Nsarray *) Result objectatindex : 0 ]) Objectforkey : @ "Name" ] ;
// Showlabel. Text = [nsstring stringwithformat: @ "Hi, % @", username];
}
}
-( Ibaction ) Clickbutton :( ID ) Sender
{
Nslog ( @ "Click" );
If ( Status = 0 ) { // Do Login
Fblogindialog * Dialog = [[[ Fblogindialog Alloc ] Initwithsession : Self . Fbsession ] Autorelease ];
[ Dialog show ];
}
Else { // Do post to wall
Fbstreamdialog * Dialog = [[[ Fbstreamdialog Alloc ] Init ] Autorelease ];
Dialog . Delegate = Self ;
Dialog . Usermessageprompt = @ "Example prompt" ;
Dialog . Attachment = @
"{"
"\" Name \ ": \" Facebook connect for iPhone \","
"\" Href \ ": \" http://developers.facebook.com/connect.php? Tab = iPhone \","
"\" Caption \ ": \" caption \","
"\" Description \ ": \" Description \","
"\" Media \":[{"
"\" Type \ ": \" image \","
"\" Src \ ": \" http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg \","
"\" Href \ ": \" http://www.facebook.com \""
"}"
"}"
"}" ;
// Dialog.tar GETID = @ "999999"; // replace this with a friend's uid
[ Dialog show ];
}
}
- ( Void ) Didreceivememorywarning {
[ Super Didreceivememorywarning ];
}
- ( Void ) Viewdidunload {
}
- ( Void ) Dealloc {
// [Self. fbbutton release];
// [Self. fbsession release];
[ Super Dealloc ];
}
@ End
Compile and run the program. Fashion Java-JavaScript mogujie.com women's clothing