Ruby facebook graph api appsecret_proof

后端 未结 2 843
情话喂你
情话喂你 2021-01-14 08:29

How can I create an appsecret_proof using Ruby for the facebook graph api?

Facebook has an example in PHP. I also saw an example in ruby in this gist.

相关标签:
2条回答
  • 2021-01-14 09:03

    I've found another way to generate the appsecret_proof for Facebook:

    OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), <app_secret>, <user_access_token>)
    

    Excerpt taken from this gist thread

    0 讨论(0)
  • 2021-01-14 09:05

    This is code that I have that works:

      hmac = OpenSSL::HMAC.new(FB_SECRET, OpenSSL::Digest::SHA256.new)
      hmac << access_token
      proof = hmac.hexdigest
      param_hash[:appsecret_proof] = proof
    

    Where FB_SECRET is the 32 digit (in my case) random string.

    In most cases access_token is the user's login authentication token (I assume current_profile.oauth_token in your case). This token must be associated with your app. If the API call is to be made with your app's credentials and not a user's credentials you can use "#{FB_APP_ID}|#{FB_SECRET}" as your access token.

    cf https://developers.facebook.com/docs/facebook-login/access-tokens

    0 讨论(0)
提交回复
热议问题