繁体   English   中英

如何在iPhone的Facebook朋友墙上发布消息

[英]How to post message on Facebook friends wall in iPhone

如何使用NEWFacebook SDK选择好友的target_id在Facebook好友墙上发布消息。 提前致谢。

NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];
[variables setObject:[NSString stringWithFormat:@"Hi."] forKey:@"message"];
[variables setObject:@"http://icon.png" forKey:@"picture"];       //http://tinyurl.com/45xy4kw
[variables setObject:@"Create post" forKey:@"name"];
[variables setObject:@"Write description." forKey:@"description"];

[_facebook requestWithGraphPath:[NSString stringWithFormat:@"/%@/feed",facebook_user_id] 
                      andParams:variables 
                  andHttpMethod:@"POST"
                    andDelegate:self];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"https://developers.facebook.com/docs/reference/dialogs/",@"link",
                                   @"Facebook Dialogs",@"name",
                                   @"Reference Documentation",@"caption",
                                   @"Using Dialogs to interact with users.",@"description",
                                   @"Facebook Dialogs are so easy!",@"message",
                                   nil];
   // [facebook requestWithGraphPath:@"me/feed" andParams:params andDelegate:self];
    //[facebook requestWithMethodName:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];
    [facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];

检查委托方法

-(void)fbDidLogin
{

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];
    [facebook requestWithGraphPath:@"me/picture" andDelegate:self];
    NSLog(@"Login Success with :%@   %@",facebook.accessToken,facebook.expirationDate);

}
-(void)fbDidLogout
{

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"])
    {
        [defaults removeObjectForKey:@"FBAccessTokenKey"];
        [defaults removeObjectForKey:@"FBExpirationDateKey"];
        [defaults synchronize];
    }
    NSLog(@"Logout Success");
}
-(void)request:(FBRequest *)request didLoad:(id)result 
{
    if(c==0)
    {
        NSData *data = [NSData dataWithData:(NSData*)result];
        UIImage *profilePic = [[[UIImage alloc] initWithData:data] autorelease];
        image1.image=profilePic;
        [self postWall];

        // NSLog(@"response is %@", result);       
        //  NSString *email =[result objectForKey:@"name"];
        // NSString *userFbId =[result objectForKey:@"id"];
        // NSLog(@"%@",email);
        // NSLog(@"%@",userFbId);
          c=1;
    }
    else
    {
        NSLog(@"%@",result);
        NSLog(@"posted!!") ;
    }
}

-(void)request:(FBRequest *)request didFailWithError:(NSError *)error
{

    NSLog(@"Failed with error: %@", [error localizedDescription]);

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM