我正在尝试让我的应用与 Facebook 进行交互。我正在使用他们的 Facebook iOS SDK (3.0) 和 Xcode 4.2。到目前为止,我实现了一个登录方法,该方法还要求为我的应用程序提供适当的权限。当我单击视图控制器中的按钮时会调用此方法,该方法位于应用程序委托中。现在登录后我想要的是将照片发布到用户墙上;此按钮所在的视图控制器是照片查看器,因此我手头有图像。我看到的将图像发布到墙上的每种方法都包括在应用程序委托中包含 Facebook 类型对象的问题。为此,您需要导入已弃用的 Facebook.h,然后手动将其添加到项目中,以便导入会导致很多错误。那么我该怎么做呢?您如何使用已弃用的标头声明此 Facebook 对象?或者您可以在没有新 SDK 中的 Facebook 对象的情况下做到这一点吗?
好的。所以我用这个部分解决了它:
- (void)facebookButtonHit:(id)sender{
DrillDownAppAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate openSessionWithAllowLoginUI:YES];
if(FBSessionStateOpen){ NSString *linkul=@"";
NSString *captt=@"";
//seteaza link-ul postului
if([self.optiune isEqualToString:@"SETURI TEMATICE"]){
linkul=@"http://www.calinevents.com/seturi.html";}
captt=@"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;下次按下按钮时,它会起作用,并且图像会与所有信息一起正确发布。下次按下按钮时,它会再次输出错误,下次正确发布时。所以它会出错,发布,错误,发布等。我能做些什么来解决这个问题?