在 Instagram 上点赞 api
Set like with Instagram api
我正在使用 Instagram 应用构建一个 ios 应用,我想在 post
上设置点赞
curl -F 'access_token=ACCESS-TOKEN' \
https://api.instagram.com/v1/media/{media-id}/likes
如何在 swift 中使用 Alamofire 发出此 curl 请求?
来自Alamofire tutorial on Github:
以下是使用 HTTP Headers 创建 POST 请求的方法:
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)
}
我正在使用 Instagram 应用构建一个 ios 应用,我想在 post
上设置点赞curl -F 'access_token=ACCESS-TOKEN' \
https://api.instagram.com/v1/media/{media-id}/likes
如何在 swift 中使用 Alamofire 发出此 curl 请求?
来自Alamofire tutorial on Github:
以下是使用 HTTP Headers 创建 POST 请求的方法:
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)
}