[GH-ISSUE #293] POSTing a text blog to Tumblr #174

Closed
opened 2026-03-03 16:46:22 +03:00 by kerem · 5 comments
Owner

Originally created by @idelfonsog2 on GitHub (Oct 18, 2016).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/293

Description:

Hi @phimage Im having the same issues and I get this as a response:

Response-Body=Optional("{\"meta\":{\"status\":400,\"msg\":\"Bad Request\"},\"response\":{\"errors\":[\"Post cannot be empty.\"]}}")}]

my code is the following

 @IBAction func postTextBlog(_ sender: AnyObject) {
        print(oauth1swift?.parameters)

        let headers = ["Accept": "application/json", "Content-Type":"application/json"]

        let parameters = [ParameterKeys.BlogType:ParameterValues.MarkdownType, ParameterKeys.Body:textBlog.text] as [String : Any]

        oauth1swift?.client.request(TMClient.sharedInstance().tumblrURL(withPathExtension: Methods.PostText), method: .POST, parameters: parameters, headers: headers, success: {
            (data, error) in
            let json = TMClient.sharedInstance().convertToJSONObject(data: data)
            print(json)
            print("hello")

            }, failure: {
                error in
                print(error)
        })


    }

(TMClient.sharedInstance().tumblrURL(withPathExtension: Methods.PostText) is essentially this:
URL: https://api.tumblr.com/v2/blog/idelfonsog2.tumblr.com/post

you can also see it below

OAuthSwiftError.response=<NSHTTPURLResponse: 0x60000022dc80> { URL: https://api.tumblr.com/v2/blog/idelfonsog2.tumblr.com/post } { status code: 400, headers {
    Connection = "keep-alive";
    "Content-Type" = "application/json; charset=utf-8";
    Date = "Tue, 18 Oct 2016 02:01:00 GMT";
    P3P = "CP=\"Tumblr's privacy policy is available here: https://www.tumblr.com/policy/en/privacy\"";
    Server = openresty;
    "Set-Cookie" = "tmgioct=5805825c60e2e80081398740; expires=Fri, 16-Oct-2026 02:01:00 GMT; Max-Age=315360000; path=/; domain=.tumblr.com; HttpOnly";

OAuth Provider (Twitter, Github, ..):

Tumblr

OAuth Version:

  • Version 1
  • Version 2

OS (Please fill the version) :

  • iOS :
  • OSX :
  • TVOS :
  • WatchOS :

Installation method:

  • Carthage
  • CocoaPods
  • Manually

Library version:

  • head
  • v1.0.0
  • v0.6
  • other: (Please fill in the version you are using.)

Xcode version:

  • 8.0 (Swift 3.0)
  • 8.0 (Swift 2.3)
  • 7.3.1
  • other: (Please fill in the version you are using.)
  • objective c
Originally created by @idelfonsog2 on GitHub (Oct 18, 2016). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/293 ### Description: Hi @phimage Im having the same issues and I get this as a response: `Response-Body=Optional("{\"meta\":{\"status\":400,\"msg\":\"Bad Request\"},\"response\":{\"errors\":[\"Post cannot be empty.\"]}}")}]` my code is the following ``` @IBAction func postTextBlog(_ sender: AnyObject) { print(oauth1swift?.parameters) let headers = ["Accept": "application/json", "Content-Type":"application/json"] let parameters = [ParameterKeys.BlogType:ParameterValues.MarkdownType, ParameterKeys.Body:textBlog.text] as [String : Any] oauth1swift?.client.request(TMClient.sharedInstance().tumblrURL(withPathExtension: Methods.PostText), method: .POST, parameters: parameters, headers: headers, success: { (data, error) in let json = TMClient.sharedInstance().convertToJSONObject(data: data) print(json) print("hello") }, failure: { error in print(error) }) } ``` (TMClient.sharedInstance().tumblrURL(withPathExtension: Methods.PostText) is essentially this: URL: https://api.tumblr.com/v2/blog/idelfonsog2.tumblr.com/post you can also see it below ``` OAuthSwiftError.response=<NSHTTPURLResponse: 0x60000022dc80> { URL: https://api.tumblr.com/v2/blog/idelfonsog2.tumblr.com/post } { status code: 400, headers { Connection = "keep-alive"; "Content-Type" = "application/json; charset=utf-8"; Date = "Tue, 18 Oct 2016 02:01:00 GMT"; P3P = "CP=\"Tumblr's privacy policy is available here: https://www.tumblr.com/policy/en/privacy\""; Server = openresty; "Set-Cookie" = "tmgioct=5805825c60e2e80081398740; expires=Fri, 16-Oct-2026 02:01:00 GMT; Max-Age=315360000; path=/; domain=.tumblr.com; HttpOnly"; ``` ### OAuth Provider (Twitter, Github, ..): Tumblr ### OAuth Version: - [x] Version 1 - [ ] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [ ] CocoaPods - [x] Manually ### Library version: - [ ] head - [ ] v1.0.0 - [ ] v0.6 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [x] 8.0 (Swift 3.0) - [ ] 8.0 (Swift 2.3) - [ ] 7.3.1 - [ ] other: (Please fill in the version you are using.) - [ ] objective c
kerem 2026-03-03 16:46:22 +03:00
Author
Owner

@phimage commented on GitHub (Oct 18, 2016):

I think the OAuthSwiftError is not fully pasted here (but I can see before the "Post cannot be empty.")

I think you can try to remove the "headers" variable. I think it's for GET request, to specify the format you want in response

Then could you post the content of "parameters"?

  • ParameterValues.MarkdownType == "text" ?? if not markdown must be specified in "format", not type

Maybe the text is not well formatted, and be encoded before passing to client...

<!-- gh-comment-id:254476771 --> @phimage commented on GitHub (Oct 18, 2016): I think the OAuthSwiftError is not fully pasted here (but I can see before the \"Post cannot be empty.\") I think you can try to remove the "headers" variable. I think it's for GET request, to specify the format you want in response Then could you post the content of "parameters"? - ParameterValues.MarkdownType == "text" ?? if not markdown must be specified in "format", not type Maybe the text is not well formatted, and be encoded before passing to client...
Author
Owner

@idelfonsog2 commented on GitHub (Oct 18, 2016):

Thanks @phimage let me try that!

the contents of ParameterValues.MarkdownType == "markdown"

<!-- gh-comment-id:254477334 --> @idelfonsog2 commented on GitHub (Oct 18, 2016): Thanks @phimage let me try that! the contents of ParameterValues.MarkdownType == "markdown"
Author
Owner

@idelfonsog2 commented on GitHub (Oct 18, 2016):

Also, where should I include the "Title" and "Body text" in my request? essentially I'm trying to publish a new post in Tumblr

<!-- gh-comment-id:254477718 --> @idelfonsog2 commented on GitHub (Oct 18, 2016): Also, where should I include the "Title" and "Body text" in my request? essentially I'm trying to publish a new post in Tumblr
Author
Owner

@phimage commented on GitHub (Oct 18, 2016):

parameters is a good place to add that, that why I ask you to past yours here
do not miss "type"

let parameters = [
"type": "text",
"format": "markdown",
"body": "my blog text" // maybe "my%20blog%20text"
]

it will be encoded to "application/x-www-form-urlencoded"

<!-- gh-comment-id:254478559 --> @phimage commented on GitHub (Oct 18, 2016): `parameters` is a good place to add that, that why I ask you to past yours here do not miss "type" ``` swift let parameters = [ "type": "text", "format": "markdown", "body": "my blog text" // maybe "my%20blog%20text" ] ``` it will be encoded to "application/x-www-form-urlencoded"
Author
Owner

@idelfonsog2 commented on GitHub (Oct 18, 2016):

Huge Thanks!!!!!! 🙇

that definitely worked!!!!

final code was: //future reference or help for anybody

oauth1swift?.client.request(TMClient.sharedInstance().tumblrURL(withPathExtension: Methods.PostText), method: .POST, parameters: parameters, headers: nil, success: {
            (data, error) in
            let json = TMClient.sharedInstance().convertToJSONObject(data: data)
            print(json)

            }, failure: {
                error in
                print(error)
        })
<!-- gh-comment-id:254567671 --> @idelfonsog2 commented on GitHub (Oct 18, 2016): # Huge Thanks!!!!!! 🙇 ### that definitely worked!!!! final code was: //future reference or help for anybody ``` oauth1swift?.client.request(TMClient.sharedInstance().tumblrURL(withPathExtension: Methods.PostText), method: .POST, parameters: parameters, headers: nil, success: { (data, error) in let json = TMClient.sharedInstance().convertToJSONObject(data: data) print(json) }, failure: { error in print(error) }) ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#174
No description provided.