Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8284229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:01:48+00:00 2026-06-08T11:01:48+00:00

Here’s code. Can anyone find why? This program is to show photos from one’s

  • 0

Here’s code. Can anyone find why?
This program is to show photos from one’s friend’s albums.

I think this program uses facebook api 3times, so there might be important point.
But i dont have any idea about things instead of this code.

  graph = Koala::Facebook::API.new(session[:access_token])
  freegraph = Koala::Facebook::API.new

  friends = graph.get_object("me/friends")
  friendsIds = Array.new
  friends.each do |f| friendsIds << f["id"] end
  fsinfo = freegraph.get_objects(friendsIds)

  @realFriends = Array.new
  fsinfo.each do |f|
    if f[1]["gender"].present? && (f[1]["gender"] != "male")
      @realFriends << f[1]
    end
  end

  rFids = @realFriends.map do |rF| rF["id"] end

  albums = graph.get_object("albums?ids="+rFids.join(","))
  album_ids = Array.new
  albums.each do |user|
     album_ids += user[1]["data"].map do |a| a["id"] end
  end

  randAlbumIds = Array.new
  20.times do
    randAlbumIds << album_ids.at(rand(album_ids.count))
  end

  imgList = graph.get_object("photos?ids="+randAlbumIds.join(","))
  imgObjs = Array.new
  imgList.each do |img|
    imgObjs += img[1]["data"]
  end
  if params[:tags].present?
    @photos = imgObjs.select do |i| i["tags"].present? end
  else
    @photos = imgObjs
  end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:01:51+00:00Added an answer on June 8, 2026 at 11:01 am

    Facebook pulls are going to be slow, that’s a given. You don’t want to do HTTP calls inside of the Rails HTTP request — also a given. So, you’ll want to move this to a background process or thread.

    But I’m more concerned about your code… You wrote

     @realFriends = Array.new
      fsinfo.each do |f|
        if f[1]["gender"].present? && (f[1]["gender"] != "male")
          @realFriends << f[1]
        end
      end
    
      rFids = @realFriends.map do |rF| rF["id"] end
    

    you’re looking for an array of female friend ideas. So I would do this:

    @female_friend_ids = fsinfo.map {|friend| friend["id"] if friend.first["gender"] != "male"}.compact
    

    This will return an array of friend ids who are not male. The map will return [nil, 3435, 656], and to get rid of the nils we call compact.

    It’s readable, and will be faster in execution and reduce garbage collection time.

    Can’t help myself. More!

    randAlbumIds = Array.new
    20.times do
      randAlbumIds << album_ids.at(rand(album_ids.count))
    end
    

    Should just be

    random_album_ids = album_ids.shuffle.take(20)
    

    (All this is just Ruby awesomeness)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code in a function I'm trying to revise. This example works
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here's a piece of code I copied from http://www.schillmania.com/content/projects/javascript-animation-1/demo/ Very simple JS animation: function
Here is my program to find all the subsets of given set. To solve
Here is my code sample, let me know if it can be further improved?
Here a simple question : What do you think of code which use try
Here is a code snippet from Network Programming for Microsoft Windows : ... //
here is code: <script type=text/javascript> function doit(){ $('table td').each(function () { if ($(this).text().trim() !=
Here my code: $(document).ready(function() { $('#mid_select').live('click', function(e){ $('#middle').load( $(this).attr('href') + ' #middle'); var page
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.