Facebook 开发 的 几个步骤 (ios)

下面这段话 是从网上拷过来的,感觉很受用

1)Update to the latest facebook-ios-sdk.
2)Instantiate with app id.



      self.facebook = [[Facebook alloc] initWithAppId:kApplicationFBID]; 

3) Authorize the app including publish_stream



  NSArray * neededPermissions = [[[NSArray alloc] initWithObjects:@"user_about_me", @"publish_stream", @"user_photos", nil] autorelease];
  [facebook authorize:neededPermissions delegate:appDelegate];

4) Ensure app delegate fBDidLogin captures and stores the access token & expiration in user defaults (for later optimization of login process).



    -(void)fbDidLogin {
        DebugLog(@"New Access Token: %@", [facebook accessToken] );
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
        [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
        [defaults synchronize];
    }

5) Confirm valid access token (non nil and not expired)...otherwise re authorize app per above.
6) Capture image to UIImage & call this noting the critical addition of the access_token. This will auto create an album for your app and put the image there and post it on the wall per my testing.

-(void)postImageToAlbum:(UIImage *)image {
  NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
    image, @"source", 
    @"caption desc", @"message",             
    nil];
  [facebook requestWithGraphPath:[NSString stringWithFormat:@"/me/photos?access_token=%@", self.facebook.accessToken]
  andParams:params andHttpMethod:@"POST" andDelegate:self];
}

7) Check for id result in FBRequestDelegate method



    -(void)request:(FBRequest *)request didLoad:(id)result {
        NSLog(@"Request didLoad: %@ ", [request url ]);
        if ([result isKindOfClass:[NSArray class]]) {
            result = [result objectAtIndex:0];
        }
        if ([result isKindOfClass:[NSDictionary class]]){

        }
        if ([result isKindOfClass:[NSData class]]) {
        }
        NSLog(@"request returns %@",result);
     }

8) DO NOT USE a test user account for testing...currently it will auth the test account and provide an access token but when you try to use graph api it will return unexpected errors. You may be alright if you are using web version vs native app setting in dev.facebook.com since supposedly you can create test users and associate them with the app but I haven't tried that.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值