mweibel/facebook.ex

Error when request to Graph API

Closed this issue · 8 comments

I request to /me

fields = ["name", "birthday", "first_name", "last_name", "address", "gender", "email"]
Facebook.me(fields, access_token)

But it raise an error:

[error] #PID<0.1058.0> running App.Endpoint terminated
Server: localhost:80 (http)
Request: POST /api/users/fb_sign_in
** (exit) an exception was raised:
    ** (UndefinedFunctionError) undefined function: :hmac.hexlify/2 (module :hmac is not available)
        :hmac.hexlify(<<101, 133, 65, 126, 95, 129, 67, 126, 54, 42, 27, 31, 160, 99, 106, 211, 84, 26, 178, 44, 77, 212, 157, 80, 223, 244, 216, 36, 8, 154, 254, 179>>, [:string, :lower])
        lib/facebook.ex:79: Facebook.me/3
        (app) web/controllers/api/user_controller.ex:31: App.Api.UserController.fb_sign_in/2
        (app) web/controllers/api/user_controller.ex:1: App.Api.UserController.action/2
        (app) web/controllers/api/user_controller.ex:1: App.Api.UserController.phoenix_controller_pipeline/2
        (app) lib/phoenix/router.ex:255: App.Router.dispatch/2
        (app) web/router.ex:1: App.Router.do_call/2
        (app) lib/app/endpoint.ex:1: App.Endpoint.phoenix_pipeline/1
        (app) lib/plug/debugger.ex:90: App.Endpoint."call (overridable 3)"/2
        (app) lib/phoenix/endpoint/render_errors.ex:34: App.Endpoint.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
        (cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4

:hmac.hexlify/2 is from the erlsha2 module which is listed as a dependency. Do you have this dependency downloaded?

Thank @mweibel for reply.
I installed it from hex: https://hex.pm/packages/facebook

{:facebook, "~> 0.4.0"}

Changed to

{:facebook,"0.4.0",[github: "mweibel/facebook.ex"]}

Then that error gone, but it raise an other error:

** (exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in :hackney_url.qs/2
        (hackney) src/hackney_lib/hackney_url.erl:309: :hackney_url.qs(["name", "birthday", "first_name", "last_name", "address", "about", "gender", "email", "middle_name", "age_range", "name_format", "timezone", "hometown", "location", "locale", {:appsecret_proof, 'xxx'}, {:access_token, "xxx"}], [])
        (hackney) src/hackney_lib/hackney_url.erl:323: :hackney_url.make_url/3
        lib/facebook/graph.ex:47: Facebook.Graph.get/3
        (app) web/controllers/api/user_controller.ex:31: App.Api.UserController.fb_sign_in/2
        (app) web/controllers/api/user_controller.ex:1: App.Api.UserController.action/2
        (app) web/controllers/api/user_controller.ex:1: App.Api.UserController.phoenix_controller_pipeline/2

Changing from hex to github shouldn't make a difference. It's the same version. Which version of hackney do you have in your deps? As you can see, the error happens within hackney itself.

Yes. I know. I'm using hackney version 1.3.1, which is required by an other module.

Ah! I know what the problem is:
Your call should be:

fields = "name,birthday,first_name,last_name,address,gender,email"
Facebook.me(fields, access_token)

Thank you. It works. I think it would be better to have code sample in README.md.

Yep, I agree! will take care of that later

I also came across this and got a different (more helpful) error when I explicitly set the github repo in mix.exs

Thanks for this module!