iphone:无法创建URL
我正在使用facebook API 我正在尝试获取id为“105502842870274”的图像的属性。为此,我尝试创建如下urliphone:无法创建URL,iphone,facebook-graph-api,Iphone,Facebook Graph Api,我正在使用facebook API 我正在尝试获取id为“105502842870274”的图像的属性。为此,我尝试创建如下url NSString *firstComponent=@"https://graph.facebook.com/105502842870274?access_token="; firstComponent=[firstComponent stringByAppendingFormat:[NSString stringWithFormat:@"%@",_accessTok
NSString *firstComponent=@"https://graph.facebook.com/105502842870274?access_token=";
firstComponent=[firstComponent stringByAppendingFormat:[NSString stringWithFormat:@"%@",_accessToken]];
NSURL *url = [NSURL URLWithString:firstComponent];
但每次url都被传递为零
如果我做错了什么,请告诉我,或者建议其他方法来获取图像的属性
提前Thanx试试这个
NSString *firstComponent=@"https://graph.facebook.com/105502842870274?access_token=";
firstComponent=[firstComponent stringByAppendingString:[NSString stringWithFormat:@"%@",_accessToken]];
NSURL *url = [NSURL URLWithString:firstComponent];
你只是做得太复杂了,而且是在额外的代码中犯了错误 您使用了
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];
这将解决您的问题。它的html编码问题
firstComponent = [firstComponent stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
另请看:Im也面临这个问题,问题似乎在于stringByAppendingFormat…append似乎喜欢添加额外的内容