LoginSignup
14

More than 5 years have passed since last update.

写真の登録で離脱させないためにもGravatarから写真をGET

Posted at

ソーシャルログインした際に顔写真を取ってくるのはよくやるけどメールから登録の場合でもGravatarから写真が取得可能。写真のファイルからのアップロードはコンバージョンが低いので取れるものはできるだけ取りたい。

Gravatarの写真は下記URLにアクセスする事で取得可能。

http://www.gravatar.com/avatar/HASH

参考: https://ja.gravatar.com/site/implement/images/

HASHの作り方

  • メールアドレスから空白文字を消す
  • メールアドレスを小文字に変換
  • md5ハッシュ変換

コードサンプル

こちらに各言語でのコードサンプルが用意されてます。親切ですね。
https://ja.gravatar.com/site/implement/

rubyの場合だと下記

# include MD5 gem, should be part of standard ruby install
require 'digest/md5'

# get the email from URL-parameters or what have you and make lowercase
email_address = params[:email].downcase

# create the md5 hash
hash = Digest::MD5.hexdigest(email_address)

# compile URL which can be used in <img src="RIGHT_HERE"...
image_src = "http://www.gravatar.com/avatar/#{hash}"

カンタン!

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14