Skip to content

Instantly share code, notes, and snippets.

@yamazaki-sensei
Last active August 12, 2016 08:40
Show Gist options
  • Select an option

  • Save yamazaki-sensei/b766a18f8e42c1939c5b78ce28da5c67 to your computer and use it in GitHub Desktop.

Select an option

Save yamazaki-sensei/b766a18f8e42c1939c5b78ce28da5c67 to your computer and use it in GitHub Desktop.
Swifterを使ってTwitterにDictionary<String, String>をそのまま投稿しようとすると401が返ってくる ref: http://qiita.com/almichest/items/60c5e455a478304ddc24
/* 投稿した文字列 */
["hoge": "fuga"]
/* 返って来たエラー */
Error Domain=NSURLErrorDomain Code=401 "HTTP Status 401: Unauthorized, Response: {"errors":[{"code":32,"message":"Could not authenticate you."}]}" UserInfo={Response-ErrorCode=32, NSLocalizedDescription=HTTP Status 401: Unauthorized, Response: {"errors":[{"code":32,"message":"Could not authenticate you."}]}, Response-Headers=<CFBasicHash 0x7f8003d01ee0 [0x1135a2a40]>{type = immutable dict, count = 10,
entries =>
0 : Server = tsa_a
1 : Content-Type = <CFString 0x7f8001eadaf0 [0x1135a2a40]>{contents = "application/json; charset=utf-8"}
2 : Set-Cookie = <CFString 0x7f8001eac7d0 [0x1135a2a40]>{contents = "guest_id=v1%3A146204234384616421; Domain=.twitter.com; Path=/; Expires=Mon, 30-Apr-2018 18:52:23 UTC"}
3 : Strict-Transport-Security = <CFString 0x7f8003e48890 [0x1135a2a40]>{contents = "max-age=631138519"}
4 : x-tsa-request-body-time = 0
5 : x-connection-hash = <CFString 0x7f8003e55cf0 [0x1135a2a40]>{contents = "c39f9646d5657d9e8c0921a2a2c0abf7"}
6 : Date = <CFString 0x7f8001ee9350 [0x1135a2a40]>{contents = "Sat, 30 Apr 2016 18:52:23 GMT"}
7 : x-response-time = 9
8 : Content-Encoding = gzip
10 : Content-Length = 89
}
class Test: NSObject {
func test() {
let swifter = Swifter(consumerKey: TWITTER_CONSUMER_KEY, consumerSecret: TWITTER_CONSUMER_SECRET, oauthToken: TWITTER_ACCESS_TOKEN, oauthTokenSecret: TWITTER_ACCESS_TOKEN_SECRET)
let dictionary = ["hoge" : "fuga"]
let string = dictionary.description
swifter.postStatusUpdate(string, success: { status in
}, failure: { error in
print(error)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment