我想实现使用 Twitter REST API 向我的 Twitter 朋友发送直接消息。我正在获取我所有朋友的 ID 并放置邀请按钮以从我的应用程序发送消息。
以下是我正在使用的函数调用 -
func sendInviteMessage(_ client: TWTRAPIClient, recepientID: String){
let statusesShowEndpoint = " https://api.twitter.com/1.1/direct_messages/events/new.json"
let params = ["recipient_id": recepientID,"message_data":"Hello","type":"message_create"]
var clientError : NSError?
let request = client.urlRequest(withMethod: "POST", urlString: statusesShowEndpoint, parameters: params, error: &clientError)
client.sendTwitterRequest(request) { (response, data, connectionError) -> Void in
if connectionError != nil {
print("Error: \(String(describing: connectionError?.localizedDescription))")
}
do {
let json = try JSONSerialization.jsonObject(with: data!, options: [])
print("json: \(json)")
} catch let jsonError as NSError {
print("json error: \(jsonError.localizedDescription)")
}
}
}
当我点击邀请按钮时,它给了我不受支持的 url 响应。