3

I need help in setting the authorization header in html file. So I used OAuth tool on dev.twitter.com and got this header content:

Authorization: OAuth oauth_consumer_key="BKsXdR3SO4hSZyFT2JevHQ", oauth_nonce="718a5099a51230e737474c7e76d21581", oauth_signature="rQ5DJWi8qMmdR76rwIOwJYUhuvc%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1341342796", oauth_token="69848552-B6geQZCA8ttirQIMKrIk47SOE541V7d5ZcYwEBUqQ", oauth_version="1.0"

Now I don't know what to do. I tried this:

<meta name="Authorization" content="OAuth" 
    oauth_consumer_key="BKsXdR3SO4hSZyFT2JevHQ", 
    oauth_nonce="b98cf39b3f8dba6286cbd1b741eb7504", 
    oauth_signature="Vgmudlrkv1dzFel9zpFztXfR6gI%3D", 
    oauth_signature_method="HMAC-SHA1", 
    oauth_timestamp="1341339879", 
    oauth_token="69848552-B6geQZCA8ttirQIMKrIk47SOE541V7d5ZcYwEBUqQ", 
    oauth_version="1.0">

But it doesn't work! I am sure doing something wrong.

Help, please!

Aram.

user1499804
  • 227
  • 2
  • 6
  • 11
  • Please describe what you are trying to do. Do you e.g. want people to login to your site using their Twitter Account? – Jan Gerlinger Jul 04 '12 at 09:42
  • No, I just want to authorize myself as owner to have an access to all data. I can't do it without simple Authorization header. But I don't know how to make it. Should I do it in my html-file or in any other? And what the hell this header is? – user1499804 Jul 04 '12 at 18:35
  • So what data do you want from Twitter and what do you want to do with it? In which language are you developing your backend? – Jan Gerlinger Jul 04 '12 at 19:13
  • I want json data with tweets' texts and locations. But it's okay, I use JS. Actually, I don't use anything except HTTP and JS. Because I'm junior developer and I have no experince. So, I thought that HTTP-header is header in HTML-file between ""-tags. I was wrong, and I can't find any useful information in Google. So I've tried to register here and to ask question. – user1499804 Jul 04 '12 at 19:28
  • You are having static HTML pages and some JS on it or a JS backend (like node.js)? For latter you should look at this: http://stackoverflow.com/questions/6377844/node-js-twitter-client – Jan Gerlinger Jul 04 '12 at 21:12

2 Answers2

4

There's an essential difference of headers. OAuth requires an "Authorization" on HTTP header, not in HTML header.

POST /1/statuses/update.json?include_entities=true HTTP/1.1
Accept: */*
Connection: close
User-Agent: OAuth gem v0.4.4
Content-Type: application/x-www-form-urlencoded
Authorization: 
        OAuth oauth_consumer_key="xvz1evFS4wEEPTGEFPHBog", 
              oauth_nonce="kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg", 
              oauth_signature="tnnArxj06cWHq44gCs1OSKk%2FjLY%3D", 
              oauth_signature_method="HMAC-SHA1", 
              oauth_timestamp="1318622958", 
              oauth_token="370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb", 
              oauth_version="1.0"
Content-Length: 76
Host: api.twitter.com

You can set this headers on a request through server-side scripting (with PHP, Python, ...)

anibalsolon
  • 131
  • 1
  • 3
  • So, how should I require future PHP-file with Post request in my html-file? – user1499804 Jul 03 '12 at 20:20
  • I think that you are misunderstanding the concept of the authentication... You can see a example of OAuth rigth in this page http://www.1stwebdesigner.com/tutorials/twitter-app-oauth-php/ – anibalsolon Jul 03 '12 at 20:27
  • I am sorry but your link was not useful. I could not find any information about making headers or requests or anything related to my question. But, thanks for help. – user1499804 Jul 03 '12 at 21:05
0

You can do HTTP requests (specifically XMLHttpRequests) from Javascript using AJAX calls (e.g. with jQuery). Check the example for the Perfect jQuery AJAX Request. Then you also can also set your request header.

Community
  • 1
  • 1
Jan Gerlinger
  • 7,361
  • 1
  • 44
  • 52