views:

322

answers:

2

Using PyFacebook I am trying to register a test user of my site with my facebook application. I can connect to the API fine and return a list of friends etc. However when trying to register an address using:

hashed_emails = facebook.hash_email('[email protected]')
accounts = [hashed_emails]
facebook.connect.registerUsers(accounts)

I get:

FacebookError: Error 100: Invalid email hash specified when trying to use connect.registerUsers(accounts)

Yet I know the hash is correct as the test hash in the documentation returns the same result:

[email protected] = 4228600737_c96da02bba97aedfd26136e980ae3761

I also know the email address used is definitely a Facebook user. Moreover connect.getUnconnectedFriendsCount() works fine and returns the expected result (0!) - suggesting the link to the App is OK.

What's going on? Is connect.registerUsers() something that would only work once I've been given 'permission' to use Friend Linking? Or is the error message I'm receiving a catch all for a number of different results? Or have I just misunderstood the use of connect.registerUsers()?

A: 

Is the hash being stored as the right type?

Also, it may be good to store the hash as a separate variable in case there's some strange race condition popping up..

Sam
What's the correct type? This is what I'm getting:>> foo = facebook.hash_email('[email protected]')>> type(foo)<type 'str'>The hash is a separate variable, I simplified for the purposes of the question. Will change to reflect.
Jon Hadley
Also, >>type(accounts) <type 'list'>
Jon Hadley
A: 

My request array to the API was incorrectly formatted. It should have been:

hashed_emails = facebook.hash_email('[email protected]')

# Wrong: accounts = [hashed_emails]
accounts = [{"email_hash": hashed_emails}] 

facebook.connect.registerUsers(accounts)

Which returned the expected response (list of registered hashes) and was further proven by connect.getUnconnectedFriendsCount() which now returns 1.

Jon Hadley