I am currently developing a page application which will allow users to schedule their page posts. As given in facebook documentation, I have to use unix time stamp ,but since the application is stored in a server it will always create a unix time stamp using mktime() respective of the server time.
Now suppose different people from different places need to schedule posts, how can i schedule their post for their given time??
You have to set a timezone for creating time-stamp.
$timezone= ''Americas/New_York';
$date = new DateTime($dateStr, new DateTimeZone($timezone));
or
date_default_timezone_set('Americas/New_York');
$date = strtotime($dateStr);
$attachment = array(
'message' => $data['facebook_text'],
'name' => $data['name'],
'link' => $this->getLinkToLatestNews(),
'description' => '',
'scheduled_publish_time' => $date
);
$facebook->api('/PAGE ID/feed/', 'post', $attachment);
Note: Time when the page post should go live, this should be between 10 mins and 6 months from the time of publishing the post.
See:
http://www.php.net/manual/en/function.date-default-timezone-set.php
http://php.net/manual/en/datetime.construct.php
Facebook Docs
Related
I can successfully get campaign stats between particular dates via the API however I need that broken down day by date rather than a total.
I can see it works for the page insights API but there doesn't seem to be documentation on the ad insights API.
I'm using the following call to get the total between dates.
https://graph.facebook.com/v2.2/act_/stats?access_token=&start_time=&end_time=
However I cannot find the documentation to break it down into day by day for one query.
This answer had a solution but didn't work.
Downloading Facebook ads statistics in background (no web browser)
Thanks!
===================================================
New info:
So I can use time_increment=1 to get a break down by day however this only works with 'date_preset' however I want to set a date range. I am using the latest API
https://graph.facebook.com/v2.2/act_{$this->accountID}/reportstats
Using 'time_ranges' will merge the data regardless of using time_increment=1
Using 'date_preset' eg last_28_days does work with time_increment.
Using 'time_interval' with midnight timestamps of my timezone (as the documentation suggested) throws the following error:
[error] => stdClass Object
(
[message] => (#100) The "time_start" and "time_stop" must be integer.
[type] => OAuthException
[code] => 100
)
They are integers! Here's my complete post data
$postData = array(
'async'=>'true',
'data_columns'=>$data_columns,
/*
'time_ranges'=>array(
array(
'day_start'=>array(
'day'=>$startDate->format("d"),
'month'=>$startDate->format("m"),
'year'=>$startDate->format("Y"),
),
'day_stop'=>array(
'day'=>$endDate->format("d"),
'month'=>$endDate->format("m"),
'year'=>$endDate->format("Y"),
),
),
),
*/
'actions_group_by'=>array('action_type'),
'time_interval'=>array(
'time_start'=>$startDate->getTimestamp() ,
'time_stop'=>$endDate->getTimestamp(),
),
//'date_preset' => 'last_28_days',
'time_increment'=>'1',
'filters'=>$filters,
'access_token'=>$this->access_token
);
Ok I had to change the format time_interval to the time_range format and it worked! The documentation says timestamps will work but it doesn't, this worked:
'time_interval'=>array(
'day_start'=>array(
'day'=>$startDate->format("d"),
'month'=>$startDate->format("m"),
'year'=>$startDate->format("Y"),
),
'day_stop'=>array(
'day'=>$endDate->format("d"),
'month'=>$endDate->format("m"),
'year'=>$endDate->format("Y"),
),
),
Events entered manually into facebook show correct times regardless of logged in state, but events uploaded via an app with datetimes to ISO-8601 (which includes time zone info ie 2013-09-27T13:00:00+01:00) result in facebook assuming event is US based for display.
Once a user is logged in, facebook shows the event correctly using the timezone info.
Its noticeable that manually entered events show a UTC+1 indicator, which does not appear on uploaded events.
Why is facebook ignoring timezone info when a visitor is not logged in, but only for uploaded events?
Is facebook requiring additional timezone data or is this a bug.
Dates are pulled from the dBase and converted to ISO8601 with:
date("c", strtotime($date))
then upload function is:
`$page = $facebook->api("/{$page_id}");
$event_data = array(
'name' => stripslashes($_POST['name']),
'description' => stripslashes(preg_replace('/£/', '£', $_POST['description'])),
'start_time' => $_POST['start_time'],
'end_time' => $_POST['end_time'],
'ticket_uri' => $_POST['ticket_uri'],
'location' => $_POST['location'],
'location_id' => $_POST['location_id'],
'no_feed_story' => ($_POST['no_feed_story'] == 1),
'picture' => $_POST['picture'],
'access_token' => $access_token,
'page_id' => $page_id);
}
$post = #$facebook->api('/' . $page_id . '/events?fields=name,picture,description,start_time,end_time,ticket_uri,location,no_feed_story', 'POST', $event_data);`
When not logged into facebook this will give:
[When] 27 September at 05:00 until 29 September at 07:00
and once logged in:
[When] 27 September at 13:00 until 29 September at 15:00
And I am in the UK so viewing from the indicated timezone (UTC+1), my IP location is London.
Editing an uploaded event the timezone is also shown as UTC+01 though that does not display when logged out ??
Some additional info, I`ve downloaded the event feed for the page and note the following errors:
An uploaded datetime of 2013-09-27T13:00:00+01:00 is changed to 2013-09-27T12:00:00+0000
and no time zone is shown, so is it expecting some other timezone data on upload?
I've now added to the code to allow editing of existing events using:
$post = $facebook->api('/' . $_POST['event_id'] . '/', 'POST', $event_data);
for update and note that editing a originally manually edited event (that has the timezone) changing the event times using above datetime format, the timezone is retained, changing location has no effect either.
Have you enabled time zone support in the Facebook app settings?
You can read about this more here.
I'm writing an app that makes a daily post as a user, and having benchmarked the PHP code that does this, it seems to take about two seconds per user. I'm dividing the work up in to chunks, and using multiple cron jobs to do each chunk. I'd like to scale to many thousands of users one day, but this kind of work load is just too much. It would take my server literally all day to post to each user one at a time using this method.
How do people normally do this? I've seen other apps that do it. Is there some way of sending all these posts off at once using just one API call? Using individual API calls per user is crazy slow.
Thanks.
On one hand, this is entirely dependent on the API.
However, you could use a multi-threaded or pseudo-parallel approach to this, such that your program sends, say, 100 HTTP POST requests at a time, rather than generating one request after another in series.
Since you're using PHP, multi-threading is out (I think) but this question is very similar to others. For example, see how these folks recommend curl_multi.
You can use batch query to achieve what you need.
The code for batch query is mentioned below. You can refer more about Facebook batch query at : http://25labs.com/tutorial-post-to-multiple-facebook-wall-or-timeline-in-one-go-using-graph-api-batch-request/
$body = array(
'message' => $_POST['message'],
'link' => $_POST['link'],
'picture' => $_POST['picture'],
'name' => $_POST['name'],
'caption' => $_POST['caption'],
'description' => $_POST['description'],
);
$batchPost[] = array(
'method' => 'POST',
'relative_url' => "/{ID1}/feed",
'body' => http_build_query($body) );
$batchPost[] = array(
'method' => 'POST',
'relative_url' => "/{ID2}/feed",
'body' => http_build_query($body) );
$batchPost[] = array(
'method' => 'POST',
'relative_url' => "/{ID3}/feed",
'body' => http_build_query($body) );
$multiPostResponse = $facebook->api('?batch='.urlencode(json_encode($batchPost)), 'POST');
Our facebook canvas app is having this problem where now, several times a day, the credits callback is passing a signed_request with the following contents:
Array
(
[algorithm] => HMAC-SHA256
[credits] => Array
(
[order_id] => 9005967273834
[order_info] => "item104"
)
[issued_at] => 1319329443
[user] => Array
(
[country] => do
[locale] => es_LA
[age] => Array
(
[min] => 0
[max] => 12
)
)
)
Notice anything missing? That's right! No user_id, buyer, or receiver is given!
We can't tell facebook what the price or description of an item is without knowing who is receiving the item.
This seems like a bad bug! This problem started happening on Oct 11, 2011
This is definitely an intermittent bug, so the only work-around is to pass the user ID from your own code into the order_info field of the item. Then use that instead of the credits receiver if the user information is missing.
I don't like that I have to do this, but it seems necessary.
I noticed this as well on my app and from what I can see the missing user IDs happen when Facebook indicates an age bracket of min 0 and max 12 years for the user. I assume that this might be the result of under 13 year olds being prevented from making purchases with Facebook credits.
Which makes me wonder what they are doing on Facebook to start with...
I am using drupal 6. I have a node called [classroom]. I would like to have a [vacancy register] associated with each classroom.
vacancy register is a cck type with:
- uid
- nid
- join date
I would like for each user to [register] for a vacancy. I think I can use flag for this.
When a user joins, I can use rules to action an email to be sent to the user and the [classroom]->cck_email field.
I would like a rule schedule to also run every 30 days ( configurable ) to alert the user to confirm their [registration].
1a. If no registration is confirmed, then 14 days later, the user is [unregistered] from the classroom.
1b. If user confirms registration ( by clicking on a button or url ). then the rule 1 runs again.
I would like to confirms if my approach to this is correct.
Update:
I have been playing around with signup, but there are the rules schedule aspect of it that I find hard customising to my liking.
I'm trying to write a rules event for signup_signup and signup_cancel, then action it through rules schedule. But there a bit of existing signup code I have to look through.
Have to do too much custom work to signup, so I thought, its easier to just do it with rules and flags. The downside is having to also create the UI for it.
For the signup module,
I have the following rules event.
Could this be reviewed please?
<http://drupal.org/node/298549>
function signup_rules_event_info() {
return array(
'signup_signup' => array(
'label' => t('User signups to classroom'),
'module' => 'Signup',
'arguments' => array(
'userA' => array('type' => 'user', 'label' => t('UserA, which adds userB.')),
'userB' => array('type' => 'user', 'label' => t('UserB, which is added to UserA\'s list.')),
),
),
);
}
I don't know what to do with the arguments list.
I haven't looked at the signup module for some time, but I think that might be a better module for your case. The flag module is a good choice too, but the signup module is more geared towards what you are doing. Users signing up for content like a classroom.