Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iphone:无法创建URL_Iphone_Facebook Graph Api - Fatal编程技术网

iphone:无法创建URL

iphone:无法创建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

我正在使用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都被传递为零

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

提前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似乎喜欢添加额外的内容