Problems getting monthly active users correctly (via Facebook Graph API) - facebook

Hey there!
I'm not able to fetch a reliable monthly active users number of my application. I tried it with FQL:
[...]
$end_time = date('Y-m-d', time()-(60*60*24*2)); // Dont' know what is correct. Sometimes it's *2 sometimes it's working with *3
$fql = $facebook->api(array(
"method" => "fql.query",
"query" => "SELECT metric, value FROM insights WHERE object_id='000000000' AND metric='application_active_users'
AND end_time=end_time_date('".$end_time."')
AND period=period('month')"
));
[...]
Looks like it's not possible to get a value up-to-the-minute. I want to get the same value as stated on my application page. But with this code it's different every day.
I also tried this solution:
$fql = $facebook->api('/000000000/insights/application_active_users/month');
but as response I only get out dated values which are a few days old:
Array
(
[data] => Array
(
[0] => Array
(
[id] => 000000000/insights/application_active_users/month
[name] => application_active_users
[period] => month
[values] => Array
(
[0] => Array
(
[value] => 166345
[end_time] => 2010-12-09T08:00:00+0000
)
[1] => Array
(
[value] => 167679
[end_time] => 2010-12-10T08:00:00+0000
)
[2] => Array
(
[value] => 168983
[end_time] => 2010-12-11T08:00:00+0000
)
)
[description] => Monthly Users who have engaged with your application or viewed your application (Unique Users)
)
)
[paging] => Array
(
[previous] => https://graph.facebook.com/000000000/insights/application_active_users/month?since=1291556506&until=1291815706
[next] => https://graph.facebook.com/000000000/insights/application_active_users/month?since=1292074906&until=1292334106
)
)
What am I doing wrong?

Facebook insights data is not available just-in-time. The insights graph will always display historic data only.
If you are interested for current monthly_active_users number look into the applications table with fql.

Related

Get list of all documents related to an account

I'm working on an app to download all notes and documents related to an account in Sugar CRM. I'm building it as a C# console application, using the web service API as a web reference in my solution.
I think I have figured out the notes part but I can't figure out the documents part. Can anyone show me how to get a list of all documents per account using the web service API calls?
I am assuming that I should use get_relationships() to get documents, but how do I get the accounts module id? I don't have access to the database.
(My client is using sugar crm version 6.7.1 corporate)
Okay, that you should use the API get_relationships. See the example to follow.
<?php
$get_relationships_parameters = array(
'session'=>$session_id,
//The name of the module from which to retrieve records.
'module_name' => 'Accounts',
//The ID of the specified module bean.
'module_id' => '13111fcd-1884-2a71-0b37-50b7d0f188f6',
//The relationship name of the linked field from which to return records.
'link_field_name' => 'documents',
//The portion of the WHERE clause from the SQL statement used to find the related items.
'related_module_query' => '',
//The related fields to be returned.
'related_fields' => array(
'id',
'name',
),
//For every related bean returned, specify link field names to field information.
'related_module_link_name_to_fields_array' => array(
),
//To exclude deleted records
'deleted'=> '0',
//order by
'order_by' => '',
//offset
'offset' => 0,
//limit
'limit' => 5,
);
$get_relationships_result = call("get_relationships", $get_relationships_parameters, $url);
?>
and you see result:
stdClass Object
(
[entry_list] => Array
(
[0] => stdClass Object
(
[id] => 8b4c0450-1922-498f-4601-52272fa6e494
[module_name] => Documents
[name_value_list] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => 8b4c0450-1922-498f-4601-52272fa6e494
)
[name] => stdClass Object
(
[name] => name
[value] => WebProxyService_A.png
)
)
)
)
[relationship_list] => Array
(
)
)
at url https://gist.github.com/amusarra/6436845 you will find the complete example. To get the account Id should use the API or get_entry get_entries.
I hope I have been of help.
Antonio

SugarCRM: how to get all contacts for an account via REST API

I am trying to get all contacts for a particular account (i know the account id) from SugarCRM using the v2 REST API.
I am sending a GET request with the following parameters:
input_type => 'JSON'
response_type => 'JSON'
method => 'get_entry_list'
rest_data => '{session:"some-valid-session-id", module_name:"Contacts", query:"contacts.account_id=some-valid-id"}'
I expect to get all contacts that are related to this accoutn, but instead I get an error "... MySQL error 1054: Unknown column 'contacts.account_id' in 'where clause'"
However, when I try to get all contacts without providing any query (query='') I get all the contacts with all their properties and I can see that there is an account_id property.
Can anyone help?
Try query:"accounts.id=some-valid-id".
It has worked for me in the past with the SOAP API.
Here's my method. It uses this wrapper class: http://github.com/asakusuma/SugarCRM-REST-API-Wrapper-Class/
/**
* returns an array of contacts that are related to the accountId passed as a param.
* The array returned will be an array of associative arrays.
* #param $accountId
* #param array $contactSelectFields optional sets the different items to return, default includes id, email1, name, title, phone_work, and description
* #return array
*
*/
public function getAllContactsAtOrganization( $accountId, $contactSelectFields=array("id", "email1", "name", "title", "phone_work", "description")) {
$sugar = new Sugar_REST( SUGAR_REST_URL, SUGAR_USER_NAME, SUGAR_PASSWORD);
$fields = array( "Accounts" => array("id", "name"),
"Contacts" => $contactSelectFields);
$options = array(
'where' => "accounts.id='$accountId'"
);
$apiResult = $sugar->get_with_related("Accounts", $fields, $options );
$contacts = array();
foreach( $apiResult['relationship_list'][0]['link_list'][0]['records'] as $almostContact) {
$curr = array();
foreach($contactSelectFields as $key) {
$curr[$key] = $almostContact['link_value'][$key]['value'];
}
$contacts[] = $curr;
}
//print_r($contacts);
return $contacts;
}
Sample Return
Array
(
[0] => Array
(
[id] => 47e1376c-3029-fc42-5ae2-51aeead1041b
[email1] => johndoe#gmail.com
[name] => Blake Robertson
[title] => CTO
[phone_work] => 8881112222
[description] => Opinionated developer that hates SugarCRM's REST API with a passion!
)
[1] => Array
(
[id] => 4c8e3fcf-8e69-ed7d-e239-51a8efa4f530
[email1] => csmith#mailinator.com
[name] => Carolyn Smith
[title] => Director of Something
[phone_work] => 832-211-2222
[description] => She's a smooth operator...
)
)
For Reference Purposes
Here's the "rest-data" (nicely formatted)
Used print_r of the php array
Array
(
[session] => 9j7fm4268l0aqm25kvf9v567t3
[module_name] => Accounts
[query] => accounts.id='e583715b-7168-5d61-5fb1-513510b39705'
[order_by] =>
[offset] => 0
[select_fields] => Array
(
[0] => id
[1] => name
)
[link_name_to_fields_array] => Array
(
[0] => Array
(
[name] => contacts
[value] => Array
(
[0] => id
[1] => email1
[2] => name
[3] => title
[4] => phone_work
[5] => description
)
)
)
[max_results] => 20
[deleted] => FALSE
)
Post Body
method=get_entry_list&input_type=JSON&response_type=JSON&rest_data={"session":"iov5a257lk5acsg9l3ll6kuej3","module_name":"Accounts","query":"accounts.id='e583715b-7168-5d61-5fb1-513510b39705'","order_by":null,"offset":0,"select_fields":["id","name"],"link_name_to_fields_array":[{"name":"contacts","value":["id","email1","name","title","phone_work","description"]}],"max_results":20,"deleted":"FALSE"}method=logout&input_type=JSON&response_type=JSON&rest_data={"session":"iov5a257lk5acsg9l3ll6kuej3"}
I'm not familiar with SugarCRM yet, but did you try with just account_id=some-valid-id ? because I also did a REST request to add a contact to sugarcrm and I didn't mention the table's name, just the fields. I didn't try this but it seems logical to me since you already mentionned the module's name, so I guess sugar kind of knows what table(s?) to look for when processing your query.

How to get the visitors state information from the tab iframe tab page via signed request?

Is there anyway to get the state information of the user visiting my facebook tab page? Currently via signed request i can get the country information. Is there a way to get state information also??
Answer is NO, check out the documentation here https://developers.facebook.com/docs/authentication/signed_request/
You get data like this
Array (
[algorithm] => HMAC-SHA256
[issued_at] => 1328803958
[page] => Array (
[id] => 114951721840
[liked] => 1
[admin] => 1 )
[user] => Array (
[country] => us
[locale] => en_US
[age] => Array ( [min] => 21 )
)
)

How to get "message" and "photo" from status message in group

Among other API's (Twitter), I am using the Facebook Graph API to create a realtime "collage" of photo's and messages from Facebook, Twitter and a designated mailbox, so that all guests at a wedding can send in photos and messages, that will be projected using a beamer during the wedding.
I have successfully implemented retrieval of type="message" and type="photo" messages, but when it comes to fetching messages of type="status", the messages are missing the "message" property. Also, if a status was posted with a photo, I cannot find any way to retrieve the photo that was attached to the status message.
Is there any way (either via Graph or by using FQL), to get the "missing" information? The status messages in the group itself (viewing the group using Facebook) contain the text and the photo, so I believe the information should be available somewhere.
The details of the message that I get, look as follows:
(I have changed or deleted some of the properties for privacy reasons).
As you can see, there is no [message] property containing the text of the status update, nor is there any reference to the photo that accompanies this status update.
Array (
[id] => xxxxxxxxxxxxxxx_xxxxxxxxxxxxxxx
[from] => Array
(
[name] => <name>
[id] => xxxxxxxxxxxxxxx
)
[to] => Array
(
[data] => Array
(
[0] => Array
(
[version] => 1
[name] => <name>
[id] => xxxxxxxxxxxxxxx
)
)
)
[actions] => Array
(
[0] => Array
(
[name] => Comment
[link] => http://www.facebook.com/xxxxxxxxxxxxxxx/posts/xxxxxxxxxxxxxxx
)
[1] => Array
(
[name] => Like
[link] => http://www.facebook.com/xxxxxxxxxxxxxxx/posts/xxxxxxxxxxxxxxx
)
)
[type] => status
[application] => Array
(
[name] => Facebook for iPhone
[namespace] => fbtouch
[id] => xxxxxxxxxx
)
[created_time] => 2012-05-26T16:00:00+0000
[updated_time] => 2012-05-26T16:00:00+0000
[likes] => Array
(
[data] => Array
(
[0] => Array
(
[name] => <name>
[id] => xxxxxxxxxxxxxx
)
)
[count] => 1
)
[comments] => Array
(
[count] => 0
)
)
I hope there is a way to retrieve the properties I need; it would be a shame if all photos that are posted as "status" message, cannot be used for the wedding presentation.

facebook signed_request user_id missing

This is data of signed_request:
Array
(
[algorithm] => HMAC-SHA256
[issued_at] => 1331219385
[page] => Array
(
[id] => xxxx602xxx551
[liked] => 1
[admin] => 1
)
[user] => Array
(
[country] => at
[locale] => de_DE
[age] => Array
(
[min] => 21
)
)
)
but user_id is missing ...
is this because user dont gave permission to the app?
I thougt an app can access all data which is public, like name or user_id
is there a way to get "user_id" without a basic permission?
You will not be able to get any identity of user prior to connection with application, this is just not possible.
You need to authorize the user to get his user id