调试Goodreads书架请求

时间:2018-11-05 04:19:50

标签: ios swift xml asynchronous oauth

当前正在使用api构建Swift iOS应用,而我遇到了一些时髦的问题。我正在尝试遍历一系列货架,并使用带有Goodreads的reviews.list API method的for循环来提取每个货架的数据。

是这样的:

func getBooksFromShelf(_ oauthswift: OAuth1Swift, userID: String, shelf: Shelf, name: String) {
        let _ = oauthswift.client.get(
            "https://www.goodreads.com/review/list?v=2",
            parameters: ["key": developerKey, "id": userID, "shelf": name, "sort": "date_added"],
            success: { response in
                let xml = SWXMLHash.parse(response.data)
                for review in xml["GoodreadsResponse"]["reviews"]["review"].all {
                    let book = review["book"]
                    let bookID = book["id"].element!.text
                    let bookTitle = book["title"].element!.text
                    let bookCoverURL = URL(string: book["image_url"].element!.text)

                    var bookAuthors = "by "
                    for author in book["authors"].all {
                        bookAuthors += author["author"]["name"].element!.text
                    }

                    let newBook = Book.init(id: bookID, title: bookTitle, authors: bookAuthors, cover: bookCoverURL)
                    shelf.books.append(newBook)
                }
        },

问题是每次循环都返回https://www.goodreads.com/review/list/USER_ID_HERE.xml?key=DEVELOPER_KEY_HERE&v=2的数据,就像根本没有向请求中添加任何参数一样。但是,当我用架子的字符串替换 name 变量时,我知道它存在,就像“当前正在读取” 一样,我得到了正确的结果https://www.goodreads.com/review/list/USER_ID_HERE.xml?key=DEVELOPER_KEY_HERE&v=2&shelf=currently-reading。 / p>

我尝试过删除参数数组并自己创建URL字符串,但这都不起作用。我看到了this thread,但由于我没有收到错误消息,只是网址错误,所以并不太一样。有什么想法吗?

0 个答案:

没有答案