[英]iphone: unable to create URL
我正在使用 facebook api
我正在尝试获取 ID 为“105502842870274”的图像的属性,为此我尝试创建一个像这样的 url
NSString *firstComponent=@"https://graph.facebook.com/105502842870274?access_token=";
firstComponent=[firstComponent stringByAppendingFormat:[NSString stringWithFormat:@"%@",_accessToken]];
NSURL *url = [NSURL URLWithString:firstComponent];
但每次 url 都是零。
如果我做错了什么或建议其他方式来获取图像的属性,请告诉我。
提前感谢
尝试这个
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];
另请参阅: 参考页
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.