任何機會,你可以使用基本身份驗證做到這一點,而不是OAuth的?我有一個類似的問題,試圖通過郵件傳遞給我在應用中實現的一些自動郵件。
我能夠通過一個大的HTTP響應正常工作。我把完整的路徑放到Keys.plist中,以便我可以將我的代碼上傳到github,並將一些參數分解爲變量,以便我可以在後面以編程方式設置它們。
// Email the FBO with desired information
// Parse our Keys.plist so we can use our path
var keys: NSDictionary?
if let path = NSBundle.mainBundle().pathForResource("Keys", ofType: "plist") {
keys = NSDictionary(contentsOfFile: path)
}
if let dict = keys {
// variablize our https path with API key, recipient and message text
let mailgunAPIPath = dict["mailgunAPIPath"] as? String
let emailRecipient = "[email protected]"
let emailMessage = "Testing%20email%20sender%20variables"
// Create a session and fill it with our request
let session = NSURLSession.sharedSession()
let request = NSMutableURLRequest(URL: NSURL(string: mailgunAPIPath! + "from=FBOGo%20Reservation%20%[email protected]<my domain>.com%3E&[email protected]<my domain>.com&to=\(emailRecipient)&subject=A%20New%20Reservation%21&text=\(emailMessage)")!)
// POST and report back with any errors and response codes
request.HTTPMethod = "POST"
let task = session.dataTaskWithRequest(request, completionHandler: {(data, response, error) in
if let error = error {
print(error)
}
if let response = response {
print("url = \(response.URL!)")
print("response = \(response)")
let httpResponse = response as! NSHTTPURLResponse
print("response code = \(httpResponse.statusCode)")
}
})
task.resume()
}
的Mailgun路徑是Keys.plist一個名爲mailgunAPIPath與字符串值:
https://API:key-<my key>@api.mailgun.net/v3/<my domain>.com/messages?
希望這有助於!
https://omarmetwally.quora.com/Integrating-the-Fitbit-API-in-iOS-apps希望它有幫助 – 7vikram7
@ 7vikram7我已經看到,但我仍然不明白 –