Fetching data from facebook using graph api - facebook

I can get desired data using facebook api like interest, movies etc. Which comes in below format.
Array
(
[data] => Array
(
[0] => Array
(
[category] => Movie
[name] => 3 Idiots Movie
[created_time] => 2012-05-11T13:22:34+0000
[id] => 441170255909978
)
[1] => Array
(
[category] => Movie
[name] => Harry Potter
[created_time] => 2011-04-11T05:44:14+0000
[id] => 156794164312
)
[2] => Array
(
[category] => Movie
[name] => Official Narnia: Voyage of the Dawn Treader
[created_time] => 2011-03-10T18:26:57+0000
[id] => 190647217857
)
[3] => Array
(
[category] => Movie general
[name] => Harry Porter
[created_time] => 2011-03-10T18:26:57+0000
[id] => 360697777345
)
How can I get details whic gives only movies and ID so that I can store in database?

You can do something of the following form:
foreach (Array['data'] as $var)
{
$ID=$var['id'];
$Name=$var['name'];
}
Note: In Array['data'], Array will be the name of the variable that you are saving this data in.

Related

Error, Fault message used AP ID: APP-80W284485P519543T

ERROR
Array
(
[0] => Array
(
[name] => ns3:FaultMessage
[attributes] => Array
(
[xmlns:ns3] => http://svcs.paypal.com/types/common
[xmlns:ns2] => http://svcs.paypal.com/types/ap
)
[0] => Array
(
[name] => responseEnvelope
[0] => Array
(
[name] => timestamp
[value] => 2014-02-20T10:17:27.045-08:00
)
[1] => Array
(
[name] => ack
[value] => Failure
)
[2] => Array
(
[name] => correlationId
[value] => 53cf284d0847f
)
[3] => Array
(
[name] => build
[value] => 9641252
)
)
[1] => Array
(
[name] => error
[0] => Array
(
[name] => errorId
[value] => 560022
)
[1] => Array
(
[name] => domain
[value] => PLATFORM
)
[2] => Array
(
[name] => subdomain
[value] => Application
)
[3] => Array
(
[name] => severity
[value] => Error
)
[4] => Array
(
[name] => category
[value] => Application
)
[5] => Array
(
[name] => message
[value] => The X-PAYPAL-APPLICATION-ID header contains an invalid value
)
[6] => Array
(
[name] => parameter
[value] => X-PAYPAL-APPLICATION-ID
)
)
)
)
Hello,
I use the sandbox AP ID: APP-80W284485P519543T and I tried another one which called Client ID, which i got from the API credentials in the profile under sandbox test accounts, both didn't work and I got this error. What is the right api ID? Where can I find it? or is some other thing wrong? Looking forward for your answer. Thank you.
Regards
Jess
The APP ID : APP-80W284485P519543T is the default APP ID for the Sandbox.
But, you are making calls to live PayPAl.
The Endpoint should be something like : https://svcs.sandbox.paypal.com/AdaptivePayments/Pay
Also, check the if you have passed any space in your APPID.
Client ID is used for making REST API calls.
The sandbox App ID is indeed APP-80W284485P519543T, so you're good if that's the value you're using for testing. I guess you just need to make sure you're trimming any whitespace or any junk off the ends, and make sure your headers are setup correctly in general.
Are you working with PHP? If so, you might want to check out my PayPal class library. It'll make your Adaptive Payments calls very simple for you.

Sugarcrm : How to retrieve related records from a custom module with Rest v4?

On a fresh install of sugarcrm 6.5 CE, I created a custom module "Groupes", with a many-to-many relationship to Accounts.
I added a record in Accounts, and one in "Groupes", and linked them together.
My goal is to use REST v4 to retrieve records in "Groupes", and the related Account records.
Using get_entry_list, I tried the following :
//retrieve records ----------------------------------------
$get_entry_list_parameters = array(
//session id
'session' => $session_id,
//The name of the module from which to retrieve records
'module_name' => "Accounts",
//The SQL WHERE clause without the word "where".
'query' => "",
//The SQL ORDER BY clause without the phrase "order by".
'order_by' => "",
//The record offset from which to start.
'offset' => "0",
//Optional. The list of fields to be returned in the results
'select_fields' => array(
'id',
'name',
),
//A list of link names and the fields to be returned for each link name
'link_name_to_fields_array' => array(
array(
'name' => 'offi1_groupes',
'value' => array(
'id',
'name',
),
),
),
//The maximum number of results to return.
'max_results' => '10000',
//To exclude deleted records
'deleted' => 0,
//If only records marked as favorites should be returned.
'Favorites' => false,
);
$get_entry_list_result = call("get_entry_list", $get_entry_list_parameters, $url);
Below you can see what I get : as you can see, the "Groupes" record are not fetched. Any clue on what went wrong ?
stdClass Object
(
[result_count] => 1
[total_count] => 1
[next_offset] => 1
[entry_list] => Array
(
[0] => stdClass Object
(
[id] => 671d043b-7c39-e2b8-66ee-5249d0d8c954
[module_name] => Accounts
[name_value_list] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[value] => 671d043b-7c39-e2b8-66ee-5249d0d8c954
)
[name] => stdClass Object
(
[name] => name
[value] => Pharmacie témoin
)
)
)
)
[relationship_list] => Array
(
[0] => stdClass Object
(
[link_list] => Array
(
[0] => stdClass Object
(
[name] => offi1_groupes
[records] => Array
(
)
)
)
)
)
)
First Get Account ID
self::$soap->get_entry_list(self::$sessionId, 'Accounts', "name='NAME'");
$acc_id = $response->entry_list[0]->id;
Get Groups ID From Relations
$get_relationships_result = self::$soap->get_relationships(self::$sessionId,"Accounts",$acc_id,"Groupes");
$groups_id = $get_relationships_result->ids[0]->id;
back and get Related Groups Information
self::$soap->get_entry_list(self::$sessionId, 'Groupes', "Groupes.id=$groupes_id");

Search in multiple array in mongodb

I want to Search a value in an array Like
`[_id] => MongoId Object (
[$id] => 511f4ce622efc34f15000001
)
[metadata] => Array (
[filename] => 6410-funny_face.gif
[parrent] => myfolder/newfolder2
[user] => Array ( >>>>>>>> i need to fetch all users
[root] => 7
[admin] => 7
[user] => 0
)
[group] => Array (
[23] => 2
)
)
[filename] => 6410-funny_face.gif
[uploadDate] => MongoDate Object (
[sec] => 1361005798
[usec] => 799000
)
[length] => 3083
[chunkSize] => 262144
[md5] => eb3846f78f461165e5bf59a05707edd1`
I need to find the user's key and value in PHP or MongoShell
im using db.collection.find(array(metadata.filename: 6410-funny_face.gif)); gives the correct answer but while in finding db.collection.find(array(metadata.user: array(7)));
db.collection.find({"metadata.user.root":7})
This should work if I understand your question.

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 "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.