Prabal Malhan
Prabal Malhan

Reputation: 21

Twitter Search Api to find mentions of word 'apple' iOS Swift

I am trying to find all the tweets mentioning the word 'apple' using SWIFT.

I am using a open source Library for twitter (https://github.com/mattdonnelly/Swifter/tree/xcode-6.3). but when calling the api , it only gives top 32 tweets whereas I want all of them. here is the code I am using

let swifter = Swifter(consumerKey: "", consumerSecret: "", appOnly: true)

        swifter.authorizeAppOnlyWithSuccess({ (accessToken, response) -> Void in
          //  println("\(accessToken)")

            swifter.getSearchTweetsWithQuery("apple", geocode: "", lang: "", locale: "", resultType: "", count: 150, until: "", sinceID: "2009-01-01", maxID: "", includeEntities: true, callback: "", success: { (statuses, searchMetadata) -> Void in


                println(statuses
                )

                }) { (error) -> Void in
                    println(error)
            }
           // println("\(response)")
        }, failure: { (error) -> Void in
          //  println(error)
        })


    }

Any suggestions on how to fix this,Moreover if any other approach is there then it also welcomed.

Upvotes: 0

Views: 756

Answers (1)

beyowulf
beyowulf

Reputation: 15331

There are millions if not billions of tweets that contain the string "apple." Twitter will not give you all of those tweets at once as it would crash your app. You will need fetch tweets process those, (100 seems to be the max) then if you would like more you can construct another fetch for example:

swifter.getSearchTweetsWithQuery("apple", geocode: nil, lang: nil, locale: nil, resultType: nil, count: 100, until: "", sinceID: nil, maxID: "", includeEntities: true, callback: "", success: { (statuses, searchMetadata) -> Void in


                print(statuses)
                //if you need more continue with another fetch but set the maxID to the ID of the last tweet from the previous fetch 
                swifter.getSearchTweetsWithQuery("apple", geocode: nil, lang: nil, locale: nil, resultType: nil, count: 150, until: nil, sinceID: nil, maxID: idOfLastTweetFromPreviousFetch, includeEntities: true, callback: nil, success: { (statuses, searchMetadata) -> Void in


                    print(statuses)


                    }) { (error) -> Void in
                        print(error)
                    }

                }) { (error) -> Void in
                    print(error)
            }

Swifter seems like a fine library, but it has little documentation. Instead you will need to use twitter's documentation to know what are the appropriate parameters to pass. For example the documentation for this end point can be found here

Upvotes: 1

Related Questions