使用facebook graph API快速发出HTTPS POST请求

时间:2018-09-05 15:02:02

标签: swift facebook-graph-api post https

当我在Google Chrome浏览器上正常使用下面的网址时,我可以创建一个新的facebook测试用户,然后取回带有用户名和密码以及其他详细信息的有效json。

https://graph.facebook.com/v3.1/2232192233718728/accounts/test-users?installed=true&name=Thomasfsdks&locale=en_US&permissions=read_stream&method=post&access_token=2232192233718728|24q_TtCeh44Z0dUVm7x5pg2U5iQ

但是,当我尝试快速执行此操作时,它似乎无法正常工作。我不确定如何使它工作。下面是swift中的代码。

    let appID = "2232192233718728"
    let urlString = "https://graph.facebook.com/v3.1/" + appID + "/accounts/test-users?"
    let url = URL(string: urlString)!

    var request = URLRequest(url: url)
    request.httpMethod = "POST"

    let name = "Thomasdasfafada"
    let accessToken = "2232192233718728|24q_TtCeh44Z0dUVm7x5pg2U5iQ"

    let postString = "installed=true&name=" + name + "&locale=en_US&permissions=read_stream&method=post&access_token=" + accessToken

    request.httpBody = postString.data(using: .utf8)


    let task = URLSession.shared.dataTask(with: request) { data, response, error in
        let responseString = String(data: data!, encoding: .utf8)

        print("here"+"responseString = \(responseString)")

    }
    task.resume()

0 个答案:

没有答案