0

How can I retrieve the individual fields/values in an object contained within the response from a POST request?

Within my variable headerObj I have the following contents printed exactly like this...

OAuth oauth_consumer_key="hrhoMzRwz8iJL",oauth_nonce="98bd41c6a18eb06317df73ec",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1423744958",oauth_version="1.0",oauth_signature="wO2nE%2B6RQluNVxiezv00iI%3D"

I have accessed this data in the following way but i need to pluck out specific fields as I dont need all of them.

var x = JSON.stringify(response)
var y = JSON.parse(x)
headerObj =  y.request.headers.Authorization

console.log(typeof(headerObj)) // string
meteorBuzz
  • 3,110
  • 5
  • 33
  • 60
  • possible duplicate of [How do I access HTTP POST data from meteor?](http://stackoverflow.com/questions/21691001/how-do-i-access-http-post-data-from-meteor) – Christian Fritz Feb 12 '15 at 17:18
  • Not really, I have accessed the data but it is retrieving the individual fields within the object I have received that I am having trouble with. – meteorBuzz Feb 12 '15 at 17:29
  • well, then it's not clear what you are asking. What have you tried to "pluck out" specific fields? I mean, my does `headerObj[the-field-you-want]` not work? – Christian Fritz Feb 12 '15 at 18:42
  • I apologise for not being clear. No this method does not work. Actually, I did 'console.log(typeof(headerObj))' and this is a string not an object. – meteorBuzz Feb 12 '15 at 19:24
  • Is regExp my only option to access the information in the string or can this be converted into an object as it is structured as an object, ie, it has name of fields followed by colon and then the value within quotation marks and then a comma? – meteorBuzz Feb 12 '15 at 19:31
  • isn't this an oauth question? this is an oauth specific header and whether you get that through meteor or REST or whatever really doesn't matter. I would search the oauth keyword. Someone must have asked about that before. The format it pretty straight forward, so an efficient parser (probably regex or splitting on comma) is probably out there for javascript. – Christian Fritz Feb 12 '15 at 23:04
  • I am using oauth, however I thought this is related to all info in headers. – meteorBuzz Feb 12 '15 at 23:28
  • 1
    @CodeCandy I tried to get this working A bit of this. Goodreads hasn't documented their oauth authentication step well. You can access what i've got so far here: https://github.com/Tarang/Meteor-Accounts-Goodreads. I started off accounts-twitter and renamed the URLs. The issue is Goodreads isn't returning callback_confirmed. But it gives back the token that you can then use to access their api. – Tarang Feb 13 '15 at 07:17
  • I will look into this thoroughly this afternoon. Thanks for taking your time to construct this. I will let you know how I get on. Since I posted questions to set up oauth API for goodreads over the last few weeks, I have finally made an authenticated api call this morning. However, I am unsure about any 'gaping' security holes, but it works. Please see the full code I will upload to this question shortly. – meteorBuzz Feb 13 '15 at 12:12
  • I have followed your instruction and successfully installed the package. I can not 'save configuration'. I get the meteor error, 403, service unknown – meteorBuzz Feb 16 '15 at 12:01

0 Answers0