我想让我的应用程序与Facebook进行交互。我正在使用他们的Facebook iOS SDK(3.0)和Xcode 4.2。到目前为止,我实现了一个登录方法,该方法还要求为我的应用程序提供适当的 权限。当我从视图控制器中点击一个按钮时,该方法被调用,该方法位于应用程序委托中。现在我想要登录后将照片发布到用户墙上;该按钮所在的视图控制器是一个照片查看器,因此我手头上有图像。我遇到的问题是,我看到将图像发布到墙上的每种方法都包括在应用程序委托中使用Facebook类型对象。为了做到这一点,你需要导入Facebook.h,这已被弃用,并且手动将其添加到项目中,这样可以导入导致很多错误。 那么我该如何做到这一点?你如何用弃用的头文件声明这个Facebook对象?或者你可以在没有新SDK中的Facebook对象的情况下做到这一点?从iOS应用程序发布图像到用户的Facebook墙
好的。所以我部分解决了这个问题:
- (void)facebookButtonHit:(id)sender{
DrillDownAppAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate openSessionWithAllowLoginUI:YES];
if(FBSessionStateOpen){ NSString *[email protected]"";
NSString *[email protected]"";
//seteaza link-ul postului
if([self.optiune isEqualToString:@"SETURI TEMATICE"]){
[email protected]"http://www.calinevents.com/seturi.html";}
[email protected]"SET TEMATIC CALIN EVENTS MODEL ";
NSInteger i=_pageIndex+1;
NSString *mno=[NSString stringWithFormat:@"%i",i];
captt= [captt stringByAppendingString:mno];
//seteaza parametrii postului
NSString *Path1 = [[NSBundle mainBundle] bundlePath];
NSString *Datele1 = [Path1 stringByAppendingPathComponent:@"Seturi.plist"];
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:Datele1];
NSDictionary *tempdicty=[[tempDict objectForKey:@"Rows"] objectAtIndex:_pageIndex];
NSString *tempurl=[tempdicty objectForKey:@"URL"];
NSMutableDictionary *postParams = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
linkul, @"link",
tempurl, @"picture",
@"Imi place acest produs Calin Events", @"name",
captt, @"caption",
@" ",@"description",
nil];
//posteaza pe Facebook
UIAlertView *incarcare=[[UIAlertView alloc] initWithTitle:@""
message:@"Se publica imaginea...\nVa rugam asteptati"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];
[incarcare setBackgroundColor:[UIColor blackColor]];
[incarcare show];
[FBRequestConnection
startWithGraphPath:@"me/feed"
parameters:postParams
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
NSString *alertText;
if (error) {
alertText = [NSString stringWithFormat:
@"S-a produs o eroare!\n Va rugam incercati din nou.",
error.domain, error.code];
} else {
alertText = [NSString stringWithFormat:
@"Imaginea a fost postata cu succes!\n Va multumim!",
[result objectForKey:@"id"]];
}
// Show the result in an alert
[[[UIAlertView alloc] initWithTitle:@""
message:alertText
delegate:self
cancelButtonTitle:@"OK!"
otherButtonTitles:nil]
show];
[incarcare dismissWithClickedButtonIndex:0 animated:YES];
}];
}
}
但现在我得到以下错误。第一次调用这个动作时,它给出一个错误代码= 5,HTTP状态代码= 400;下一次该按钮被击中时,它会起作用,并且图像会与所有信息一起正确发布。下一次按下按钮时,它会再次输出错误,下一次正确发布。所以它出现错误,发布,错误,发布等。 我能做些什么来解决这个问题?