在我的iPhone應用程序中,我想發送文本以及圖像到Facebook。如何在iPhone SDK中使用Facebook API發送文字和圖片?
目前Facebook API建議有單獨的用戶權限,使我們能夠這樣做。
有沒有一種方法可以在我的項目中只使用一個API?
如果是,我們該怎麼做?
引用任何文章或教程,將是非常有益
請幫助&建議。
謝謝
在我的iPhone應用程序中,我想發送文本以及圖像到Facebook。如何在iPhone SDK中使用Facebook API發送文字和圖片?
目前Facebook API建議有單獨的用戶權限,使我們能夠這樣做。
有沒有一種方法可以在我的項目中只使用一個API?
如果是,我們該怎麼做?
引用任何文章或教程,將是非常有益
請幫助&建議。
謝謝
我不確定這是可能的。我已經發布圖像與下一個解決方案:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
takedPhoto, @"picture",
@"some text", @"message",
nil];
[facebook requestWithGraphPath:@"/me/photos" andParams:params
andHttpMethod:@"POST" andDelegate:self];
takedPhoto是UIImage。 但它只是在相冊中加載照片(如果您在登錄時允許權限,則批准它)。 我不知道如何使用此上傳圖像在牆上張貼信息... Regards,
是的,你可以這樣做。
請看看下面所有的方法:
- (IBAction)uploadPhoto:(id)sender {
[self postOnFacebook];
}
//發帖子和照片在Facebook上功能
-(void)postOnFacebook
{
NSString *strPostMessage = [self createMessageForPostOnFacebook:74.112 withLongitude:21.85];
//UIImage *img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:objClsProductSearch.strProductImageURL]]];
//UIImage *img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg"]]];
UIImage *img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://d1xzuxjlafny7l.cloudfront.net/wp-content/uploads/2011/08/HUDTutorial.jpg"]]];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
strPostMessage,@"message",img, @"source",
nil];
[_facebook requestWithGraphPath:@"/me/photos"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];
[img release];
}
//在Facebook上張貼
-(NSString *)createMessageForPostOnFacebook:(double)pfltLatitude withLongitude:(double)pfltLongitude
{
//NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%f,%f&output=csv",pfltLatitude, pfltLongitude];
//NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%f,%f&output=csv",@"", @""];
//NSError* error;
//NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSASCIIStringEncoding error:&error];
//NSArray *listItems = [locationString componentsSeparatedByString:@","];
NSString *strMessage = nil;
/*if([[listItems objectAtIndex:0] isEqualToString:@"200"])
{
strMessage = [NSString stringWithFormat:@"I found a %@ using BH for iPhone \n Location : %@ \n Latitude : %f & Longitude : %f \n Product Rating : %d",objClsProductSearch.strCategoryname,[locationString substringFromIndex:6],appDelegate.dblLatitude,appDelegate.dblLongitude,btnTmp.tag];
}*/
strMessage = [NSString stringWithFormat:@"I found a %@ using BH for iPhone \n Location : %@ \n Latitude : %f & Longitude : %f \n Product Rating : %d", @"Cat Name", @"Location", 74.112, 21.85, 1];
return strMessage;
}
創建消息
我希望你能成功使用上面的代碼。
如有任何困難,請告知我。
在你的應用程序委託中,看看下面的方法是否實現。
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
//return [[controller facebook] handleOpenURL:url];
//return [[objPage2ViewController facebook] handleOpenURL:url];
return [[[self.navigationController topViewController] facebook] handleOpenURL:url];
}
乾杯