Skip to content

Instantly share code, notes, and snippets.

@rdetert
Created July 20, 2011 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdetert/1094648 to your computer and use it in GitHub Desktop.
Save rdetert/1094648 to your computer and use it in GitHub Desktop.
Rake Task to set whether a user has been Facebook verified or not using Omniauth
namespace :facebook do
desc "Check if users have updated their Facebook verification status"
task :update_user_verifiation_status => :environment do
require 'omniauth'
# get all users who are not currently verified
@users = User.joins(:authentications, :profile).where(:"authentications.provider" => "facebook", :"user_profiles.facebook_verified" => 0).select("users.id AS id, authentications.uid, authentications.access_token, user_profiles.facebook_verified")
@users.each do |user|
FB = OmniAuth::Strategies::Facebook.new("nothing")
client = ::OAuth2::Client.new("nothing", "nothing", FB.client_options)
cached_token = user.access_token
access_token = ::OAuth2::AccessToken.new(client, cached_token)
FB.instance_variable_set("@access_token", access_token)
@auth_hash = FB.auth_hash rescue nil
if @auth_hash
user = User.find(user.id)
user.profile.facebook_verified = !!@auth_hash['extra']['user_hash']['verified'] rescue false
user.profile.save
end
end
end
end
@rdetert
Copy link
Author

rdetert commented Jul 20, 2011

TODO: re-write using libcurl and make use of FB's new Batching feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment