2013-04-01 43 views
5

我想在我的iOS應用創建類似按鈕通過使用Open graph api給出Facebook的捲曲狀使用開放圖形

curl -X POST \ 
    -F 'access_token=USER_ACCESS_TOKEN' \ 
    -F 'object=OG_OBJECT_URL' \ 
    https://graph.facebook.com/[User FB ID]/og 

.likes POST請求。

對於它,我已經取得POST請求即

NSString *stringurl=[NSString stringWithFormat:@"{access_token=AAAE08AxGmwghghghOWAxMZBz6jZAaRTUYTRMakJln3VdAeUju6E6tFn2I9feY5wtGatTm2KIgXoXYFZB0pTPQt2Oj0sNaRuX3AZDZD}&{object=http://www.google.com}&https://graph.facebook.com/100002097766610/og.likes"]; 

NSURL *url = [NSURL URLWithString: stringurl]; 
NSMutableURLRequest *request1 = [NSMutableURLRequest requestWithURL:url]; 

[request1 setURL:url]; 
[request1 setHTTPMethod:@"POST"]; 
[request1 setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; 

NSError *error; 
NSURLResponse *response; 
NSData *data = [NSURLConnection sendSynchronousRequest:request1 returningResponse:&response error:&error]; 
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 
NSLog(@"string..:%@",string); 

但是我得到空字符串。可能是我做錯了url字符串。如果有人知道如何製作捲髮帖子請求。請給我一些想法。

感謝所有。

回答

3

我附下面的一些代碼:

HTTP POST請求的身體數據應位於「體」,所以我用「setHttpBody:」方法。

NSString *userId = @"Your ID Facebook ID"; 
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/og.likes", userId]]; 
NSMutableURLRequest *request1 = [NSMutableURLRequest requestWithURL:url]; 
[request1 setURL:url]; 
[request1 setHTTPMethod:@"POST"]; 
NSString *body=[NSString stringWithFormat:@"access_token=YOUR_APP_ACCESS_TOKEN&object=OG_OBJECT_URL"]; 
[request1 setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]]; 

NSError *error; 
NSURLResponse *response; 
NSData *data = [NSURLConnection sendSynchronousRequest:request1 returningResponse:&response error:&error]; 
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 
NSLog(@"string..:%@",string); 
+0

非常感謝你爲這個偉大的編碼..我試圖解決這個問題從最後一個星期..你已經解決了它。你今天過得如此美好。 –