2011-05-01 58 views
1

我与Facebook的APIiphone:无法创建URL

我试图用这个ID为“105502842870274”,以获取图像的属性的工作,我试图创建一个URL像这样

NSString *[email protected]"https://graph.facebook.com/105502842870274?access_token="; 
firstComponent=[firstComponent stringByAppendingFormat:[NSString stringWithFormat:@"%@",_accessToken]]; 

NSURL *url = [NSURL URLWithString:firstComponent]; 

但每次url传递为零。

请让我知道如果我做错了什么或建议其他方式来获取图像的属性。

Thanx提前

+0

林也面临这样的问题,问题似乎在于stringByAppendingFormat ...追加似乎想增加额外的东西 – 2011-06-02 11:29:17

回答

1

这将解决您的问题。它的html编码问题。

firstComponent = [firstComponent stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; 

也期待:reference page

1

试试这个

NSString *[email protected]"https://graph.facebook.com/105502842870274?access_token="; 
firstComponent=[firstComponent stringByAppendingString:[NSString stringWithFormat:@"%@",_accessToken]]; 

NSURL *url = [NSURL URLWithString:firstComponent]; 
1

你只是这样做太复杂,它是在你犯了一个错误的额外代码。您使用stringByAppendingFormat而不是stringByAppendingString

对于一个更简单的解决方案,只是做:

NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/105502842870274?access_token=%@", _accessToken]]; 

或者,如果你想访问后弦:

NSString* firstComponent = [NSString stringWithFormat:@"https://graph.facebook.com/105502842870274?access_token=%@", _accessToken] 
NSURL* url = [NSURL URLWithString:firstComponent];