jbwebdesign Posted February 8, 2014 Report Posted February 8, 2014 Hello guys, i am trying to create an api request but the problem i have is that the code is not written in PHP. they only have Ruby and Python samples. can someone please help me so that i can create a request to the api with PHP. import hashlib import hmac import urllib2 import time API_KEY = 'YOUR-API-KEY' API_SECRET = 'YOUR-API-SECRET' def get_http(url, body=None): opener = urllib2.build_opener() nonce = int(time.time() * 1e6) message = str(nonce) + url + ('' if body is None else body) signature = hmac.new(API_SECRET, message, hashlib.sha256).hexdigest() opener.addheaders = [('ACCESS_KEY', API_KEY), ('ACCESS_SIGNATURE', signature), ('ACCESS_NONCE', nonce)] try: return opener.open(urllib2.Request(url, body)) except urllib2.HTTPError as e: print e return e print get_http('https://thewebsite.com/api/v1/account/').read() Quote
administrator Posted March 30, 2014 Report Posted March 30, 2014 Hi, I just noticed this post now - sorry. Just in case you are still having problems and for others to see ... So, not knowing Python, I would just give up! ... Just kidding! Ok, so what I would do is find what each of these methods do, for instance: urllib2: http://docs.python.org/2/howto/urllib2.html And then just rebuild the overall flow of this code. Once you've done these two things, you should be able to source out the PHP functions that do the same. So, having only looked at Python 8000 years ago, I would say that the code is making an HTTP Get request and sending encoded HTTP headers. Not sure since I have no idea of the context. Stefan Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.