Created
July 20, 2011 09:26
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: re-write using libcurl and make use of FB's new Batching feature.