2017-02-16 61 views
0

我建立與Instagram的應用的iOS應用程序,我希望能在一個崗位設置類似於Instagram的API

curl -F 'access_token=ACCESS-TOKEN' \ 
https://api.instagram.com/v1/media/{media-id}/likes 

如何使迅速使用Alamofire該捲曲要求設置什麼樣的?

回答

0

Alamofire tutorial on Github:

下面是如何創建一個POST請求處理HTTP標頭:

let headers: HTTPHeaders = [ 
    "Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", 
    "Accept": "application/json" 
] 

Alamofire.request("https://httpbin.org/headers", headers: headers).responseJSON { response in 
    debugPrint(response) 
} 

現在,創建一個POST到Instagram的API:

let headers: HTTPHeaders = [ 
    "access_token": \(YOUR_ACCESS_TOKEN) 
] 

Alamofire.request("https://api.instagram.com/v1/media/\(media-id)/likes", headers: headers).responseJSON { response in 
    print(response) 
} 

// you could also explicitly define the request as a POST 
Alamofire.request("https://api.instagram.com/v1/media/\(media-id)/likes", method: .post, headers: headers) 

編輯# 1:

稍微更改了代碼以反映OP的工作解決方案。

let headers: HTTPHeaders = [ 
    "access_token": \(YOUR_ACCESS_TOKEN) 
] 

Alamofire.request("https://api.instagram.com/v1/media/\(media-id)/likes", method: .post, parameters: header).responseJSON { response in 
    print(response) 
} 
+0

我提出請求,但它說它缺少訪問令牌,我正在使用alamofire和響應json –

+1

沒關係,我自己做了。我已經將**標題**更改爲**參數**並添加了**方法:.post **,它開始工作! –