Couldn't resolve `"code":32,"message":"Could not authenticate you."`

oauth
login

#1

I tried getting request_token by command but ``“code”:32,“message”:“Could not authenticate you.”` happened.

Are there some wrong settings or OAuth params? I wrote below code, tried by this and checked “Twitter OAuth Tool”. However I couldn’t find any problems…
what is actual situation caused code 32 error?

I’m very glad if you help me…

#!/bin/sh

consumer_key="consumer_key"
consumer_key_secret="consumer_secret"
hmac_key="${consumer_key_secret}&"

function urlencode {
 ruby -r cgi -e "puts CGI.escape(\""$1"\")"
}

callback="http://172.0.0.1"

oauth_nonce=`cat /dev/urandom | LC_CTYPE=C  tr -dc "a-zA-Z0-9" | fold -w 32 | head -n 1`
oauth_nonce=`urlencode $oauth_nonce`

timestamp=`date +%s`
params="oauth_callback=${callback}&auth_consumer_key=${consumer_key}&oauth_nonce=${oauth_nonce}&oauth_signature_method=HMAC-SHA1&oauth_timestamp=${timestamp}&oauth_version=1.0"
signature_base_string_authorization_header=`ruby -r cgi -e "puts CGI.escape \"$params\""`
callback=`urlencode $callback`

http_method="POST"
url_path="https://api.twitter.com/oauth/request_token"
encoded_url_path=`urlencode $url_path`

signature_base_string="${http_method}&${encoded_url_path}&${signature_base_string_authorization_header}"

oauth_signature=`echo -n "${signature_base_string}" | openssl sha1 -hmac "${hmac_key}" -binary | openssl base64`
oauth_signature=`urlencode $oauth_signature`

authorization_header_value="oauth_callback=${callback}, oauth_consumer_key=${consumer_key}, oauth_nonce=${oauth_nonce}, oauth_signature=${oauth_signature}, oauth_signature_method=HMAC-SHA1, oauth_timestamp=${timestamp}, oauth_version=1.0"

authorization_header="Authorization: OAuth ${authorization_header_value}"

curl -v --request 'POST' "${url_path}" --header "${authorization_header}" 

command result:

*   Trying 104.244.42.130...
* Connected to api.twitter.com (104.244.42.130) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
* Server certificate: api.twitter.com
* Server certificate: DigiCert SHA2 High Assurance Server CA
* Server certificate: DigiCert High Assurance EV Root CA
> POST /oauth/request_token HTTP/1.1
> Host: api.twitter.com
> User-Agent: curl/7.43.0
> Accept: */*
> Authorization: OAuth oauth_callback=http%3A%2F%2F172.0.0.1, oauth_consumer_key=XXXXXXXX, oauth_nonce=j4myD2tdcXe6BStnRtNXn3LWn8AwkRhK, oauth_signature=hsABur9iDWaOXW7Bw%2FDoIeAvS0g%3D, oauth_signature_method=HMAC-SHA1, oauth_timestamp=1476115165, oauth_version=1.0
>
< HTTP/1.1 401 Authorization Required
< cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
< content-disposition: attachment; filename=json.json
< content-length: 64
< content-type: application/json; charset=utf-8
< date: Mon, 10 Oct 2016 15:59:26 GMT
< expires: Tue, 31 Mar 1981 05:00:00 GMT
< last-modified: Mon, 10 Oct 2016 15:59:26 GMT
< pragma: no-cache
< server: tsa_a
< set-cookie: guest_id=v1%3A147611516682490588; Domain=.twitter.com; Path=/; Expires=Wed, 10-Oct-2018 15:59:26 UTC
< status: 401 Unauthorized
< strict-transport-security: max-age=631138519
< www-authenticate: OAuth realm="https://api.twitter.com"
< x-connection-hash: a84969779a57d6830ff9ef4ee1ff9782
< x-content-type-options: nosniff
< x-frame-options: SAMEORIGIN
< x-response-time: 9
< x-transaction: 005baf820077ef39
< x-twitter-response-tags: BouncerCompliant
< x-xss-protection: 1; mode=block
<
* Connection #0 to host api.twitter.com left intact
{"errors":[{"code":32,"message":"Could not authenticate you."}]}

Sincerely,