Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 通过Alamofire在SWIFT中使用Twitter API_Ios_Swift_Api_Twitter - Fatal编程技术网

Ios 通过Alamofire在SWIFT中使用Twitter API

Ios 通过Alamofire在SWIFT中使用Twitter API,ios,swift,api,twitter,Ios,Swift,Api,Twitter,我现在试着发送一个简单的查询-在邮递员中,它对我来说很好,但在SWIFT中,我根本无法让它工作 我的代码如下所示: func TWITTER_getPosts(username:String){ let headers = [ "screen_name": "username", "authorization": "OAuth oauth_consumer_key=\"<KEY>\",oauth_token=\"&l

我现在试着发送一个简单的查询-在邮递员中,它对我来说很好,但在SWIFT中,我根本无法让它工作 我的代码如下所示:

func TWITTER_getPosts(username:String){


        let headers = [
            "screen_name": "username",
            "authorization": "OAuth oauth_consumer_key=\"<KEY>\",oauth_token=\"<KEY>\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"1469246792\",oauth_nonce=\"n6Sxbq\",oauth_version=\"1.0\",oauth_signature=\"<KEY>\"",
            "include_rts": "false"
        ]

        Alamofire.request(.GET, "https://api.twitter.com/1.1/statuses/user_timeline.json", parameters: headers)
            .responseJSON { response in
                print(response.request)  // original URL request
                print(response.response) // URL response
                print(response.data)     // server data
                print(response.result)   // result of response serialization

                if let JSON = response.result.value {
                    print("JSON: \(JSON)")
                }
        }
    }
func TWITTER\u getPosts(用户名:String){
让标题=[
“屏幕名称”:“用户名”,
“授权”:“OAuth OAuth\u消费者密钥=\”\”,OAuth\u令牌=\“\”,OAuth\u签名\u方法=\“HMAC-SHA1\”,OAuth\u时间戳=\“1469246792\”,OAuth\u nonce=“n6Sxbq\”,OAuth\u版本=“1.0\”,OAuth\u签名=“\”,
“包括”:“假”
]
请求(.GET,“https://api.twitter.com/1.1/statuses/user_timeline.json,参数:标题)
.responseJSON{中的响应
打印(response.request)//原始URL请求
打印(response.response)//URL响应
打印(response.data)//服务器数据
print(response.result)//响应序列化的结果
如果让JSON=response.result.value{
打印(“JSON:\(JSON)”)
}
}
}
我总是以失败告终

错误=( { 代码=215; message=“错误的身份验证数据。”


请求方法的一个参数不正确。 如果要传递头,则不应在参数中传递头,应按以下方式传递头:

let headers = [
 "Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==",
 "Accept": "application/json"
]

Alamofire.request(.GET, "https://httpbin.org/get", headers: headers)
     .responseJSON { response in
         debugPrint(response)
     }

headers:headers
应该是一个不错的选择。

你试过使用STTwitter吗?我没有在Swift中使用它的经验,但如果它是可桥接的,它可能会有帮助。我们如何生成签名?