nov/fb_graph — Issue #193: After creating a campaign, the posting attributes overwrites return attributes from Facebook 
Author: bighostkim
Created: 2012-02-14 20:07:35+00:00
State: open

This matters to files;

lib/fb_graph/connections/ad_campaigns.rb
lib/fb_graph/connections/ad_groups.rb

When I post to FB to create an object, I have a FbGraph returned from FB
However, this object has not the value of FB assigned, i.e. id, but the value of that I posted

For example with connections/ad_campaigns.rb line 15

AdCampaign.new(ad_campaign[:id], options.merge(ad_campaign).merge(
:access_token => options[:access_token] || self.access_token
))

because returned value has only two keys, id/data, it does not overwrite the posting values(options)
for example,

options will look like this,

{"id"=>nil, "account_id"=>326936304, "name"=>"Test", "start_time"=>nil, "end_time"=>nil, "daily_budget"=>#, "lifetime_budget"=>nil, "campaign_status"=>nil, :redownload=>1}]

and ad_campaign will look like this with "&redownload=1",

{"id"=>"6004083181864", "data"=>{"campaigns"=>{"6004083181864"=>{"account_id"=>326936304, "campaign_id"=>6004083181864, "name"=>"Test", "daily_budget"=>100, "campaign_status"=>1, "daily_imps"=>0, "id"=>"6004083181864", "start_time"=>1329249409, "end_time"=>nil, "updated_time"=>1329249409}}}}

so, connections/ad_campaigns.rb line 15 should be like this

AdCampaign.new(ad_campaign[:id], options.merge( ad_campaign["data"] || ad_campaign ).merge(
:access_token => options[:access_token] || self.access_token
))

The same goes to ad_groups, or more(that I don't find yet)

Allen

Here is my console log

======= [FbGraph] API REQUEST STARTED =======
POST /act_326936304/adcampaigns HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 190
Host: graph.facebook.com

account_id=326936304&name=Test&daily_budget=100.0&redownload=1&access_token=AAAFRAPMNd0kBAPukjU8ZAIBEeJxZC5atind1odgr4AefjwZCke7wCXbESXXZBU4HJ8ZBcNPZCrZAce4W3hVehq9lRmkdsQhmJa75RtvVcp6AAZDZD

Status: 200 OK
Access-Control-Allow-Origin: *
Cache-Control: private, no-cache, no-store, must-revalidate
Content-Type: text/javascript; charset=UTF-8
Expires: Sat, 01 Jan 2000 00:00:00 GMT
Pragma: no-cache
X-FB-Rev: 509320
X-FB-Debug: qmtrV6zZuE1rdRegZmcd436B9V8fBWvOKppnz5pWk9M=
X-Cnection: close
Date: Tue, 14 Feb 2012 19:40:27 GMT
Content-Length: 0

{"id":"6004083173864","data":{"campaigns":{"6004083173864":{"account_id":326936304,"campaign_id":6004083173864,"name":"Test","daily_budget":100,"campaign_status":1,"daily_imps":0,"id":"6004083173864","start_time":1329248427,"end_time":null,"updated_time":1329248427}}}}
======= [FbGraph] API REQUEST FINISHED =======
[:ad_campaign, {"id"=>"6004083173864", "data"=>{"campaigns"=>{"6004083173864"=>{"account_id"=>326936304, "campaign_id"=>6004083173864, "name"=>"Test", "daily_budget"=>100, "campaign_status"=>1, "daily_imps"=>0, "id"=>"6004083173864", "start_time"=>1329248427, "end_time"=>nil, "updated_time"=>1329248427}}}}]
[:options, {"id"=>nil, "account_id"=>326936304, "name"=>"Test", "start_time"=>nil, "end_time"=>nil, "daily_budget"=>#, "lifetime_budget"=>nil, "campaign_status"=>nil, :redownload=>1}]
[:fb_obj, #]