Skip to content

Instantly share code, notes, and snippets.

@satomacoto
Forked from apolloclark/Twitter API with Curl
Created September 9, 2017 01:12
Show Gist options
  • Select an option

  • Save satomacoto/5571137b64a0f87d0122fb86741773c7 to your computer and use it in GitHub Desktop.

Select an option

Save satomacoto/5571137b64a0f87d0122fb86741773c7 to your computer and use it in GitHub Desktop.

Revisions

  1. @apolloclark apolloclark renamed this gist Dec 22, 2015. 1 changed file with 12 additions and 11 deletions.
    23 changes: 12 additions & 11 deletions Twitter API on Bash → Twitter API with Curl
    Original file line number Diff line number Diff line change
    @@ -19,17 +19,6 @@ sudo apt-get install jq



    # do a search with curl, pretty print with jq
    # @see http://curl.haxx.se/docs/manpage.html
    # @see https://dev.twitter.com/rest/public/search
    curl -s -H "$(cat ~/twitter_api)" --data 'q=%40twitterapi' --get 'https://api.twitter.com/1.1/search/tweets.json' | jq '.'

    # do a search, print tweet text
    curl -s -H "$(cat ~/twitter_api)" --data 'q=%40twitterapi' --get 'https://api.twitter.com/1.1/search/tweets.json' | jq '.statuses[].text'




    # example, fully written
    curl
    --get 'https://api.twitter.com/1.1/search/tweets.json'
    @@ -53,3 +42,15 @@ curl

    # example, as one-liner
    curl -G 'https://api.twitter.com/1.1/search/tweets.json' -d 'q=%23archaeology' -h "$(cat ~/twitter_api)" -s





    # do a search with curl, pretty print with jq
    # @see http://curl.haxx.se/docs/manpage.html
    # @see https://dev.twitter.com/rest/public/search
    curl -s -H "$(cat ~/twitter_api)" -d 'q=%40twitterapi' -G 'https://api.twitter.com/1.1/search/tweets.json' | jq '.'

    # do a search, print tweet text
    curl -s -H "$(cat ~/twitter_api)" -d 'q=%40twitterapi' -G 'https://api.twitter.com/1.1/search/tweets.json' | jq '.statuses[].text'
  2. @apolloclark apolloclark revised this gist Dec 22, 2015. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions Twitter API on Bash
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,13 @@ Authorization: OAuth oauth_consumer_key="XXXXXX", oauth_nonce="11111111", oauth_
    # @see https://stedolan.github.io/jq/manual/
    sudo apt-get install jq

    # test requests
    # @see https://dev.twitter.com/rest/tools/console





    # do a search with curl, pretty print with jq
    # @see http://curl.haxx.se/docs/manpage.html
    # @see https://dev.twitter.com/rest/public/search
  3. @apolloclark apolloclark revised this gist Dec 22, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Twitter API on Bash
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,8 @@ Authorization: OAuth oauth_consumer_key="XXXXXX", oauth_nonce="11111111", oauth_
    # @see https://stedolan.github.io/jq/manual/
    sudo apt-get install jq

    # do a search, pretty print with jq
    # do a search with curl, pretty print with jq
    # @see http://curl.haxx.se/docs/manpage.html
    # @see https://dev.twitter.com/rest/public/search
    curl -s -H "$(cat ~/twitter_api)" --data 'q=%40twitterapi' --get 'https://api.twitter.com/1.1/search/tweets.json' | jq '.'

  4. @apolloclark apolloclark revised this gist Dec 22, 2015. 1 changed file with 34 additions and 3 deletions.
    37 changes: 34 additions & 3 deletions Twitter API on Bash
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,47 @@
    # create an account, create an app
    https://apps.twitter.com/
    # @see https://apps.twitter.com/

    # retrieve the access tokens
    https://dev.twitter.com/oauth/reference/post/oauth2/token
    # @see https://dev.twitter.com/oauth/reference/post/oauth2/token

    # create the file ~/twitter_api
    nano ~/twitter_api
    Authorization: OAuth oauth_consumer_key="XXXXXX", oauth_nonce="11111111", oauth_signature="XXXXXX", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1450728725", oauth_token="99999-XXXXXX", oauth_version="1.0"

    # install JQ
    # @see https://stedolan.github.io/jq/manual/
    sudo apt-get install jq

    # do a search, pretty print with jq
    # @see https://dev.twitter.com/rest/public/search
    curl -s -H "$(cat ~/twitter_api)" --data 'q=%40twitterapi' --get 'https://api.twitter.com/1.1/search/tweets.json' | jq '.'
    curl -s -H "$(cat ~/twitter_api)" --data 'q=%40twitterapi' --get 'https://api.twitter.com/1.1/search/tweets.json' | jq '.'

    # do a search, print tweet text
    curl -s -H "$(cat ~/twitter_api)" --data 'q=%40twitterapi' --get 'https://api.twitter.com/1.1/search/tweets.json' | jq '.statuses[].text'




    # example, fully written
    curl
    --get 'https://api.twitter.com/1.1/search/tweets.json'
    --data '&q=%23archaeology'
    --header ''Authorization: OAuth oauth_consumer_key="AAAA", oauth_nonce="9999", oauth_signature="AAAA", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1450742465", oauth_token="9999-AAAA", oauth_version="1.0"'
    --silent

    # example, loading auth headers from file
    curl
    --get 'https://api.twitter.com/1.1/search/tweets.json'
    --data 'q=%23archaeology'
    --header "$(cat ~/twitter_api)"
    --silent

    # example, using option short-hand
    curl
    -G 'https://api.twitter.com/1.1/search/tweets.json'
    -d 'q=%23archaeology'
    -h "$(cat ~/twitter_api)"
    -s

    # example, as one-liner
    curl -G 'https://api.twitter.com/1.1/search/tweets.json' -d 'q=%23archaeology' -h "$(cat ~/twitter_api)" -s
  5. @apolloclark apolloclark revised this gist Dec 21, 2015. 1 changed file with 8 additions and 4 deletions.
    12 changes: 8 additions & 4 deletions Twitter API on Bash
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,16 @@
    # create an account, get the API access keys
    # create an account, create an app
    https://apps.twitter.com/

    # retrieve the access tokens, here:
    # retrieve the access tokens
    https://dev.twitter.com/oauth/reference/post/oauth2/token

    # create the file ~/twitter_api
    nano ~/twitter_api
    Authorization: OAuth oauth_consumer_key="XXXXXX", oauth_nonce="11111111", oauth_signature="XXXXXX", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1450728725", oauth_token="99999-XXXXXX", oauth_version="1.0"

    # do a search
    # install JQ
    sudo apt-get install jq

    # do a search, pretty print with jq
    # @see https://dev.twitter.com/rest/public/search
    curl -s -H "$(cat ~/twitter_api)" --get --data 'q=%40twitterapi' 'https://api.twitter.com/1.1/search/tweets.json' | jq '.'
    curl -s -H "$(cat ~/twitter_api)" --data 'q=%40twitterapi' --get 'https://api.twitter.com/1.1/search/tweets.json' | jq '.'
  6. @apolloclark apolloclark revised this gist Dec 21, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Twitter API on Bash
    Original file line number Diff line number Diff line change
    @@ -9,4 +9,4 @@ Authorization: OAuth oauth_consumer_key="XXXXXX", oauth_nonce="11111111", oauth_

    # do a search
    # @see https://dev.twitter.com/rest/public/search
    curl -H "$(cat ~/twitter_api)" --get --data 'q=%40twitterapi' 'https://api.twitter.com/1.1/search/tweets.json'
    curl -s -H "$(cat ~/twitter_api)" --get --data 'q=%40twitterapi' 'https://api.twitter.com/1.1/search/tweets.json' | jq '.'
  7. @apolloclark apolloclark revised this gist Dec 21, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion Twitter API on Bash
    Original file line number Diff line number Diff line change
    @@ -2,9 +2,11 @@

    # retrieve the access tokens, here:
    https://dev.twitter.com/oauth/reference/post/oauth2/token

    # create the file ~/twitter_api
    nano ~/twitter_api
    Authorization: OAuth oauth_consumer_key="XXXXXX", oauth_nonce="11111111", oauth_signature="XXXXXX", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1450728725", oauth_token="99999-XXXXXX", oauth_version="1.0"

    # do a search
    curl --get 'https://api.twitter.com/1.1/search/tweets.json' --data 'q=%40twitterapi' --header "$(cat ~/twitter_api)"
    # @see https://dev.twitter.com/rest/public/search
    curl -H "$(cat ~/twitter_api)" --get --data 'q=%40twitterapi' 'https://api.twitter.com/1.1/search/tweets.json'
  8. @apolloclark apolloclark revised this gist Dec 21, 2015. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions Twitter API on Bash
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,10 @@
    # create an account, get the API access keys

    # ~/twitter_api

    # retrieve the access tokens, here:
    https://dev.twitter.com/oauth/reference/post/oauth2/token
    # create the file ~/twitter_api
    nano ~/twitter_api
    Authorization: OAuth oauth_consumer_key="XXXXXX", oauth_nonce="11111111", oauth_signature="XXXXXX", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1450728725", oauth_token="99999-XXXXXX", oauth_version="1.0"

    # do a search
    curl --get 'https://api.twitter.com/1.1/search/tweets.json' --data 'q=%40twitterapi' --header "$(cat ~/twitter_api)"
  9. @apolloclark apolloclark created this gist Dec 21, 2015.
    6 changes: 6 additions & 0 deletions Twitter API on Bash
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    # create an account, get the API access keys

    # ~/twitter_api


    curl --get 'https://api.twitter.com/1.1/search/tweets.json' --data 'q=%40twitterapi' --header "$(cat ~/twitter_api)"