2011-05-01 55 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];