我试图在Instagram API上发布POST来改变用户的关系但我却无法接听电话。我做了一些研究,一个人说要将action=follow
部分放在POST Data
中。我进一步搜索了这个,仍然无法通过我的请求。
let request = NSMutableURLRequest(URL: NSURL(string: "https://api.instagram.com/v1/users/\(user.id)/relationship?access_token=\(account.accessToken)")!)
let key = "action=follow"
let mastData = key.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)!
let mastLength = "\(mastData.length)"
request.HTTPMethod = "POST"
request.HTTPBody = mastData
request.addValue(mastLength, forHTTPHeaderField: "Content-Length")
request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
let operation = AFHTTPRequestOperation(request: request)
operation.responseSerializer = AFJSONResponseSerializer()
operation.setCompletionBlockWithSuccess({ (_, result) -> Void in
let result = result as! NSDictionary
let data = result["data"] as! NSDictionary
completion(true)
}) { (_, error) -> Void in
completion(false)
}
此外,我知道user.id
有效且account.accessToken
也有效,因为我已在应用的其他部分成功使用它们。