iPhone:无法创建 URL

发布于 2024-11-05 00:48:03 字数 435 浏览 1 评论 0原文

我正在使用 facebook apis

我正在尝试获取 id 为“105502842870274”的图像的属性,为此我尝试创建一个像这样的 url

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

NSURL *url = [NSURL URLWithString:firstComponent];

,但每次 url 都传递为 nil。

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

提前感谢

I am working with facebook apis

I am trying to fetch attributes of an image with id '105502842870274' for this I tried to create a url like this

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

NSURL *url = [NSURL URLWithString:firstComponent];

but every time url is passes as nil.

Please let me know if I am doing something wrong or suggest someother way to fetch attributes of an image.

Thanx in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

虫児飞 2024-11-12 00:48:03

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

firstComponent = [firstComponent stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];

另请参阅:参考页面

this will resolve your issue. Its html encoding problem.

firstComponent = [firstComponent stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];

also look: reference page

面犯桃花 2024-11-12 00:48:03

试试这个

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

NSURL *url = [NSURL URLWithString:firstComponent];

try this

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

NSURL *url = [NSURL URLWithString:firstComponent];
醉南桥 2024-11-12 00:48:03

你只是做得太复杂了,而且你在额外的代码中犯了错误。

您使用了 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];

You're just doing it too complicated, and it is in your extra code that you made an error.

You used stringByAppendingFormat instead of stringByAppendingString.

For an even easier solution, just do :

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

Or if you want to access the string later :

NSString* firstComponent = [NSString stringWithFormat:@"https://graph.facebook.com/105502842870274?access_token=%@", _accessToken]
NSURL* url = [NSURL URLWithString:firstComponent];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文