我想让我的应用与Facebook互动。我正在使用他们的Facebook iOS SDK(3.0)和Xcode 4.2。到目前为止,我实现了一个登录方法,该方法也要求适当的 我的应用的权限。当我从视图控制器中单击按钮时,将调用此方法,该方法位于应用程序委托中。现在登录后我想要的是将照片发布到用户墙上;此按钮所在的视图控制器是照片查看器,因此我手头有图像。我的问题是,我看到将图像发布到墙上的每种方法都包括在app委托中使用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;下次按下按钮时,它会起作用,图像会与所有信息一起正确发布。下次按下该按钮时,它会在下次正确发布时再次输出错误。所以它出错,发布,错误,发布等。 我该怎么做才能解决这个问题?
答案 0 :(得分:0)
我将代码的前几行更改为此,现在可以了:
DrillDownAppAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
if(![FBSession.activeSession isOpen]){[appDelegate openSessionWithAllowLoginUI:YES];
}
if([FBSession.activeSession isOpen]){[appDelegate openSessionWithAllowLoginUI:NO];}