ios Instagram api POST 关系端点使用 Alamofire - 错误

标签 ios swift api instagram alamofire

我在我的应用程序中使用 swift

我正在尝试使用 Alamofire 发布关系(关注)与范围(“follower_list+relationships”)

注意:我正在使用沙盒用户进行测试

用这段代码

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)
        }
    }

但仍然收到此消息??

ERROR responseSerializationFailed(Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}))

有什么想法吗??

最佳答案

如果您尝试发布 json,我怀疑您需要使用 encoding: JSONEncoding.default 更改编码

The JSONEncoding type creates a JSON representation of the parameters object, which is set as the HTTP body of the request. The Content-Type HTTP header field of an encoded request is set to application/json.

github 上的使用

关于ios Instagram api POST 关系端点使用 Alamofire - 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47643107/

相关文章:

ios - 无法将类型 'Published<Bool>.Publisher' 的值转换为预期的参数类型 'Binding<Bool>'

swift - 发射器碰撞不起作用?

json - 如何在 Swift 中解码 JWT(JSON 网络 token ) token ?

java - 我应该在 Post 方法中设置哪个 IP 地址?

python - 工件批量更新

php - 亚马逊 MWS 提交价格设置 Feed

ios - swift : equivalent to respondToSelector

ios - 将 UI 元素连接到数组中的插槽

ios - UICollectionView 仅在用户双击时调用 didSelectItemAtIndexPath,当用户单击时不会调用

ios - 如何等待已在运行的功能完成