我在应用程序中使用swift
,我正在尝试使用Alamofire
发布范围(" follower_list 关系")的关系(" follower_list 关系")注意:我正在使用沙盒用户进行测试
使用此代码
let userid = "testAccount"
let urlString = "https://api.instagram.com/v1/users/(userid)/relationship?access_token=(INSTAGRAM_IDS.INSTAGRAM_Token)&action=follow"
Alamofire.request(urlString).responseJSON { response in switch response.result {
case .success(let JSON):
let response = JSON as! NSDictionary
let userModel = response
print("SUCCESS")
print(userModel)
case .failure(let error):
print("ERROR")
print(error)
}
}
也尝试了这个
let userid = "testAccount"
let urlString = "https://api.instagram.com/v1/users/(userid)/relationship?access_token=(INSTAGRAM_IDS.INSTAGRAM_Token)"
let parameters: Parameters = ["action": "follow"]
Alamofire.request(urlString, method: .post, parameters: parameters, encoding: URLEncoding.default, headers: nil).responseJSON { response in switch response.result {
case .success(let JSON):
let response = JSON as! NSDictionary
let userModel = response
print("SUCCESS")
print(userModel)
case .failure(let error):
print("ERROR")
print(error)
}
}
但仍然收到此消息??
错误 响应式恢复failed(alamofire.aferror.resseserializationfailurereason.jsonserializationFailed(错误域= nscocoaerrordomain code = 3840
任何想法??
如果您想发布JSON,我怀疑您需要使用encoding: JSONEncoding.default
JSONENCODING类型创建了参数对象的JSON表示形式,该对象将其设置为请求的HTTP主体。编码请求的内容类型HTTP标头字段设置为应用程序/json。
github上的用法
我发现了问题。...我一直在使用帐户用户名,而不是用户ID有区别...我的坏
您可以从(搜索)端点API获取用户ID或使用类似网站https://smashballoon.com/instagram-feed/find-instagram-user-id/
您放置了用户名,您将获得ID