I keep getting the following error when I try to invoke the Facebook REST API Call:
Connect.registerUsers
Error Code: 100 - param accounts must be an array
JSON based response (from Facebook):
{"error_code":100,"error_msg":"param accounts must be an array.","request_args":
[{"key":"accounts","value":"{email_hash:5232156322_55ddgvc3db5ddcf218049dd564da2x06}"},
{"key":"api_key","value":"23b2c4c6a23445fbffssf8aab96a5e5"},
{"key":"format","value":"JSON"},{"key":"method","value":"Connect.registerUsers"},{"key":"sig","value":"3sd54153a31382fa6e72eecf3c57d7c9"},{"key":"v","value":"1.0"}],"message":"Unknown exception","code":0}
I set up the Java code to invoke the REST end point using HttpClient like this:
String API_KEY = "23b2c4c6a23445fbffssf8aab96a5e5";
String toConnectRegisterUsersSignature =
"accounts="
+ "{email_hash:" + emailHash + "}"
+ "api_key=" + API_KEY
+ "format=JSON"
+ "method=Connect.registerUsers"
+ "v=1.0"
+ "0c786155bd3cxe8228d924542da5gf2";
String connectRegisterUsersSignature = SimpleMd5.MD5(toConnectRegisterUsersSignature);
NameValuePair[] connectRegisterUsersParameters =
{
new NameValuePair("accounts", "{email_hash:" + emailHash + "}"),
new NameValuePair("api_key", API_KEY),
new NameValuePair("format", "JSON"),
new NameValuePair("method", "Connect.registerUsers"),
new NameValuePair("sig", connectRegisterUsersSignature),
new NameValuePair("v", "1.0")
};
Tried the following combinations and I still get the same error!
Signature: "accounts=" + "[email_hash=" + emailHash + "]"
new NameValuePair("accounts", "[email_hash=" + emailHash + "]")
Signature: "accounts=" + "email_hash[" + emailHash + "]"
new NameValuePair("accounts", "email_hash[" + emailHash + "]")
Signature: "accounts=" + "email_hash(" + emailHash + ")"
new NameValuePair("accounts", "email_hash(" + emailHash + ")")
Signature: "accounts=" + "[email_hash=" + emailHash + "]"
new NameValuePair("accounts", "[email_hash=" + emailHash + "]")
Signature: "accounts=" + "email_hash=" + emailHash
new NameValuePair("accounts", "email_hash=" + emailHash)
Signature: "accounts=" + "[{email_hash:" + emailHash + "}]"
new NameValuePair("accounts", "[{email_hash:" + emailHash + "}]"),
Does anyone know how to construct this array that the response is requesting?
Happy programmi开发者_如何学Gong and thank you for taking the time to read this.
I'm not sure how much help this will be, but the following works for me in Python using the PyFacebook wrapper (sorry, not familiar with the Java method):
hashed_email = facebook.hash_email('mary@example.com')
# >>> hashed_email
# >>> '4228600737_c96da02bba97aedfd26136e980ae3761'
regaccounts = [{"email_hash": hashed_email}]
facebook.connect.registerUsers(regaccounts)
The PyFacebook wrapper sends the api_key (which, incidently is the only other required parameter)
P.S. If it's any consolation, your question made me realise where I'd gone wrong in a similar case!
精彩评论