15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/email_to_face.rb', line 15
def self.user_image(email)
begin
url = URI.encode("https://graph.facebook.com/search?q=#{email}&type=user&access_token=#{@access_token}")
uri = URI.parse(url)
req = Net::HTTP.new(uri.host, 443)
req.use_ssl = true
response = req.request_get(uri.path + '?' + uri.query)
result = JSON.parse(response.body)
rescue Exception => e
puts e.inspect
return nil
end
raise result["error"]["message"] if result["error"]
result['data'] == [] ? nil : "https://graph.facebook.com/#{result['data'][0]['id']}/picture?type=#{@image_type || 'large'}"
end
|