Hi guys,
I have been struggling with this for over two days and I could use your help. Here's the problem:
Whenever a request is made to the Facebook REST server, we have to send an additional parameter called "sig". This sig is generated using the following algorithm:
<?php
$secret = 'Secret Key'; // where 'Secret Key' is your application secret key
$args = array(
'argument1' => $argument1,
'argument2' => $argument2); // insert the actual arguments for your request in place of these example args
$request_str = '';
foreach ($args as $key => $value) {
$request_str .= $key . '=' . $value; // Note that there is no separator.
}
$sig = $request_str . $secret;
$sig = md5($sig);
?>
More information about this: http://wiki.developers.facebook.com/index.php/How_Facebook_Authenticates_Your_Application
I have been trying to reproduce this piece of code in Python, here is my attempt:
def get_signature(facebook_parameter):
sig = ""
for key, value in facebook_parameter.parameters:
sig += key + "=" + value
sig += facebook_parameter.application_secret
return hashlib.md5(sig).hexdigest()
facebook_paremeter.parameters is a list that looks like this:
[('api_key', '...'), ('v', '1.0'), ('format', 'JSON'), ('method', '...')]
and facebook_paremeter.application_secret is a valid app secret.
This code is running on the Google App Engine development platform (if that makes any difference). Python 2.6.4.
Can somebody help me find out where my code is going wrong?
Thanks, Sri