cURL command returns HTTP 404 Not Found


#1

I created a Twitter application. I clicked the Test OAuth button in the upper right hand corner. I left all of the input fields default, and clicked See OAuth signature for this request. I copy and pasted the cURL command into my Lubuntu terminal. I am getting an HTTP 404 Not Found error. Am I performing this test correctly? I created the app correctly… I created the app, generated API keys and access tokens, I even tried setting the permissions to read and write and then regenerated all of the keys and tokens. Still not working.

Here is the below curl command and output. I deleted the consumer key and oauth token from the output for privacy reasons:

root@li725-25:~# curl --get ‘https://api.twitter.com/1.1/’ --header ‘Authorization: OAuth oauth_consumer_key="", oauth_nonce=“b900788d446ae6620ba52265f29e16e0”, oauth_signature=“1tWpVqAKQnPLvmx%2BIokq%2BTOjlKc%3D”, oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1404346777”, oauth_token="", oauth_version=“1.0”’ --verbose

  • About to connect() to api.twitter.com port 443 (#0)
  • Trying 199.59.149.232… connected
  • successfully set certificate verify locations:
  • CAfile: none
    CApath: /etc/ssl/certs
  • SSLv3, TLS handshake, Client hello (1):
  • SSLv3, TLS handshake, Server hello (2):
  • SSLv3, TLS handshake, CERT (11):
  • SSLv3, TLS handshake, Server key exchange (12):
  • SSLv3, TLS handshake, Server finished (14):
  • SSLv3, TLS handshake, Client key exchange (16):
  • SSLv3, TLS change cipher, Client hello (1):
  • SSLv3, TLS handshake, Finished (20):
  • SSLv3, TLS change cipher, Client hello (1):
  • SSLv3, TLS handshake, Finished (20):
  • SSL connection using ECDHE-RSA-RC4-SHA
  • Server certificate:
  • subject: C=US; ST=California; L=San Francisco; O=Twitter, Inc.; OU=Twitter Security; CN=api.twitter.com
  • start date: 2014-04-08 00:00:00 GMT
  • expire date: 2014-10-10 23:59:59 GMT
  • subjectAltName: api.twitter.com matched
  • issuer: C=US; O=VeriSign, Inc.; OU=VeriSign Trust Network; OU=Terms of use at https://www.verisign.com/rpa ©10; CN=VeriSign Class 3 Secure Server CA - G3
  • SSL certificate verify ok.

GET /1.1/ HTTP/1.1
User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
Host: api.twitter.com
Accept: /
Authorization: OAuth oauth_consumer_key=“pYRrArpI83zaosEn7seq52H4R”, oauth_nonce=“b900788d446ae6620ba52265f29e16e0”, oauth_signature=“1tWpVqAKQnPLvmx%2BIokq%2BTOjlKc%3D”, oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1404346777”, oauth_token=“1308354156-50aDrkFg21M8MY8fa1xcm5mjn5Dc336sjVuewha”, oauth_version=“1.0”

< HTTP/1.1 404 Not Found
< cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
< content-length: 4429
< content-type: text/html; charset=UTF-8
< date: Thu, 03 Jul 2014 00:23:45 GMT
< expires: Tue, 31 Mar 1981 05:00:00 GMT
< last-modified: Thu, 03 Jul 2014 00:23:45 GMT
< pragma: no-cache
< server: tfe
< set-cookie: dnt=; domain=.twitter.com; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT
< set-cookie: lang=en; path=/
< set-cookie: lang=en; path=/
< set-cookie: _twitter_sess=BAh7CCIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7ADoHaWQiJWFhYjMwYWQzNmQ0N2FjMjE0NmUxMTk3%250AMjUzOTdjYmYyOg9jcmVhdGVkX2F0bCsIDQmb%252BUYB–bf3cc8ec316d52379aca4ce4d7ce323c3b4e6949; domain=.twitter.com; path=/; secure; HttpOnly
< set-cookie: guest_id=v1%3A140434702558193980; Domain=.twitter.com; Path=/; Expires=Sat, 02-Jul-2016 00:23:45 UTC
< status: 404 Not Found
< strict-transport-security: max-age=631138519
< vary: Accept-Encoding
< x-content-type-options: nosniff
< x-frame-options: SAMEORIGIN
< x-mid: e6b670308ba4c462d9ca3dd6ab23524773b8d4f3
< x-rate-limit-limit: 15
< x-rate-limit-remaining: 9
< x-rate-limit-reset: 1404347703
< x-transaction: c05263338a05781a
< x-ua-compatible: IE=edge,chrome=1
< x-xss-protection: 1; mode=block
<

Twitter / ?
      <h1>Sorry, that page doesn’t exist!</h1>
      <p>Thanks for noticing&mdash;we're going to fix it up and have things back to normal soon.</p>
      <form class="search-404" action="https://twitter.com/search" method="get">
        <input id="search_q" name="q" type="text" aria-label="Search query" placeholder="Search for a topic, full name, or @username">
        <input class="btn" id="search_submit" type="submit" value="Search">
      </form>

    <div class="footer">

        <ul class="languages">

            <li><a data-language="ar" href="#">العربية</a></li>

            <li><a data-language="da" href="#">Dansk</a></li>

            <li><a data-language="de" href="#">Deutsch</a></li>

            <li><a data-language="en" href="#">English</a></li>

            <li><a data-language="en-gb" href="#">EnglishUK</a></li>

            <li><a data-language="es" href="#">Español</a></li>

            <li><a data-language="fa" href="#">فارسی</a></li>

            <li><a data-language="fi" href="#">Suomi</a></li>

            <li><a data-language="fil" href="#">Filipino</a></li>

            <li><a data-language="fr" href="#">français</a></li>

            <li><a data-language="he" href="#">עִבְרִית</a></li>

            <li><a data-language="hi" href="#">हिन्दी</a></li>

            <li><a data-language="hu" href="#">Magyar</a></li>

            <li><a data-language="id" href="#">Bahasa Indonesia</a></li>

            <li><a data-language="it" href="#">Italiano</a></li>

            <li><a data-language="ja" href="#">日本語</a></li>

            <li><a data-language="ko" href="#">한국어</a></li>

            <li><a data-language="msa" href="#">Bahasa Melayu</a></li>

            <li><a data-language="nl" href="#">Nederlands</a></li>

            <li><a data-language="no" href="#">Norsk</a></li>

            <li><a data-language="pl" href="#">Polski</a></li>

            <li><a data-language="pt" href="#">Português</a></li>

            <li><a data-language="ru" href="#">Русский</a></li>

            <li><a data-language="sv" href="#">Svenska</a></li>

            <li><a data-language="th" href="#">ภาษาไทย</a></li>

            <li><a data-language="tr" href="#">Türkçe</a></li>

            <li><a data-language="ur" href="#">اردو</a></li>

            <li><a data-language="zh-cn" href="#">简体中文</a></li>

            <li><a data-language="zh-tw" href="#">繁體中文</a></li>

        </ul>

      <ul class="links">
        <li class="first">&copy; 2014 Twitter</li>
        <li><a href="https://twitter.com/about">About</a></li>
        <li><a href="https://support.twitter.com">Help</a></li>
        <li><a href="http://status.twitter.com/">Status</a></li>
      </ul>
    </div>
  </div>
</div>
<script src="https://abs.twimg.com/errors/404-7fdc040757e48e020c4fe7c892326307.js"></script>
* Connection #0 to host api.twitter.com left intact * Closing connection #0 * SSLv3, TLS alert, Client hello (1): root@li725-25:~#

#2

Hi, thanks for this great question! I think the issue here is that you are not trying to call any specific API endpoint. The curl command you pasted shows you just hitting https://api.twitter.com/1.1/ which is the “base” url for our API, but doesn’t have any data to return. You would want to try something else, maybe https://api.twitter.com/1.1/get/help/configuration which should return some data and not a 404 page not found.

You can find a full list of valid endpoints here https://dev.twitter.com/docs/api/1.1

Another tip is that you could optionally use our open source twurl tool instead of curl to simplify your testing. You can learn more about that at https://github.com/twitter/twurl