FQL: query for event table returns venue.name instead of venue.id - facebook-php-sdk

When making a query to get event details I seem to get venue.name instead of venue.id in the result set. Has there been an unannounced change in the table structure or am I doing something wrong. The Graph API Explorer gives the venue.id yet when using FQL through PHP SDK in my own web site it's the venue.name I get.
Heres the code:
$fql='{
"event_info": "SELECT name,description, pic_small,pic_big, eid,venue,location FROM event WHERE eid ='.$_GET['id'].'",
"event_venue":"SELECT name, username, page_id, location FROM page WHERE name IN (SELECT venue.id FROM #event_info)"
}';
$setup = array(
'method' => 'fql.multiquery',
'queries' => $fql,
'callback' => ''
);
$result = $facebook->api($setup);
This leads to the "event_venue" result set to be empty.
Here's the dump:
Array
(
[0] => Array
(
[name] => event_info
[fql_result_set] => Array
(
[0] => Array
(
[eid] => 410351692336116
[venue] => Array
(
[name] => Boothill
)
[location] => Boothill
)
)
)
[1] => Array
(
[name] => event_venue
[fql_result_set] => Array
(
)
)
)

If I test this query
SELECT name,description, pic_small,pic_big, eid,venue,location
FROM event WHERE eid ='410351692336116'
using the FQL tab (!) in the Graph API explorer, I get
"venue": {
"id": 126049334121592
}
and not the venue’s name.
And doing a multiquery like your’s with the second query being
"event_venue":"SELECT name, username, page_id, location FROM page
WHERE page_id IN (SELECT venue.id FROM #event_info)"
I’m getting the venue info as well.
Could you please check if you get a different result if you do your queries not using your $setup array with
'method' => 'fql.multiquery',
but just
$facebook->api('/fql?q='.urlencode('{ "event_info": "…", "event_venue": "… FROM page
WHERE page_id IN (SELECT venue.id FROM #event_info)" }'));
instead?

I've run into this issue today and spent quite some time troubleshooting it. It seems to be related to the Access Token. When I use my App's Access Token to request the venue data, for some venues all I I get is the venue.name field. However, if I use the Graph API Explorer to generate a different token, I get the venue.id field as expected.
I went as far as to replace the Graph API Explorer's generated Access Token with my App Token, and sure enough all I received back was venue.name.

Related

Wordpress REST API "orderby" meta value

I am execting following GET request to obtain data form wordpress
http://domain:port/wp-json/wp/v2/announcement?_fields=announcement_category,effective_start_date,effective_end_date
The result is as below
[
{
"announcement_category": [
216
],
"effective_start_date": "2020-03-27",
"effective_end_date": "2020-04-16"
},
{
"announcement_category": [
215
],
"effective_start_date": "2020-03-25",
"effective_end_date": "2020-03-31"
}]
I need to sort/order my response in the ASC order of the "announcemet_category" value. (there is always one value for this array)
I know "orderby" does not support meta_values.
How to enable meta_value sorting and how can I execute my query for this.
Please help
You should be able to sort on a meta value using:
$q = new WP_Query(
// Other query params e.g. post type...
array(
'meta_key' => 'announcement_category',
'orderby' => 'meta_value_num',
'order' => 'ASC',
)
);
Based on this answer.
However I think your issue is that as you've pointed out, announcement_category is an array rather than a number, which you won't be able to sort on.
If you can't change announcement_category to a number rather than an array, you can use a usort to sort the results of your WordPress query, before sending the API response:
$arr1 = array(
array('announcement_category'=>array(216)),
array('announcement_category'=>array(218)),
array('announcement_category'=>array(202)),
array('announcement_category'=>array(300)),
);
function sortByOrder($a, $b) {
return $a['announcement_category'][0] - $b['announcement_category'][0];
}
usort($arr1, 'sortByOrder');
print_r($arr1); // Ordered ascendingly
Alternatively, you can use javascript on the client side to sort the response as required:
announcements.sort(function (a, b) {
return a[announcement_category][0] - b[announcement_category][0];
});
Array Sort

NHibernate QueryOver - Doing Fetches and OrderBy -> What Syntax to use?

All,
I have a query as such:
_AddOrderBy(sortOptions, query)
.Fetch(x => x.ImageType).Eager
.Fetch(x => x.User).Eager
.Fetch(x => x.Partner).Eager
.Inner.JoinAlias(x => x.Partner, () => p).Fetch(x => x.Company).Eager
.Skip(startIndex)
.Take(pageSize)
.List<ImageRequest>();
In the above QueryOver I call _AddOrderBy() method which adds an order by clause. The challenge I face is how do I create an "order by" that references a property (ordering by "CompanyName") that lies within the following association path without conflicting with my Fetch()/Inner joins:
ImageRequest.Partner.Company.CompanyName
Inside my _AddOrderBy() I have this:
Partner p = null;
Company comp = null;
order = query.Inner.JoinAlias(x => x.Partner, () => p)
.Inner.JoinAlias(x => x.Company, () => comp)
.OrderBy(x => comp.CompanyName);
But this gives me a run time exception stating that I have duplicate key (referring to Partner) in the criteria. I can see that this is conflicting with my eager fetching.
My questions is:
How do I add an "order by" so it works with my Fetching.
The beauty of using an Alias in QueryOver is that you don't have to use Fetch or JoinAlias in your _AddOrderBy() method again if the Join happens in the query already. You only need to declare the Alias with the same name.
Therefore your _AddOrderBy() can just look like this:
Partner p = null;
Company comp = null;
order = query
.Inner.JoinAlias(x => p.Company, () => comp) // you can use p here if it was used in the query before
.OrderBy(x => comp.CompanyName);
The reason this works is this: If you put the whole code into one method it will obviously work. Splitting it into two methods still works, because Partner p is not a reference to an object in memory but an Alias that is simply translated into a string for the SQL query.

Doctrine2 query with QueryBuilder returns array instead of object

I want to get doctrin2 query result in object format but it gives me in array format.
I tried but I can't succeed.
This is demo query but if I want to apply similar types of join in another query than also requires results in object format but in all of them.
Can you have any solution?
return $this->createQueryBuilder("u")
->select("u.id as userid, up.id as profileid, u.username, u.email, u.isactive, up.firstname, up.lastname, up.profileimage, up.address, up.zipcode, up.biography")
->innerjoin("u.userprofile", "up")
->where("u.id = :userid")
->setParameter(":userid", $userid)
->getQuery()
->getResult();
ResultSet :
Array
(
[userid] => 4
[profileid] => 3
[username] => Test user
[email] => testuser#yahoo.com
[isactive] => 1
[firstname] => MyFname
[lastname] => MyLname
[profileimage] => 5111ea998c9476c2231180050d5ad64dc3298fe0.jpeg
[address] => My Address
[zipcode] => 36102555
[biography] => This is my first symfon2.3 project.
)
May be it's because you 're not loading the object fully, as you're loading it partially. That's why ORM is converting it automatically. You can use partial keyword to force it to load as partial object, but be carefull.

how to populate text area with database value before form load in drupal 7?

I have used hook_form_FORM_ID_alter( ) function to alter a menu_edit_menu form to add few fields. I ve stored the values from those fields in a table when submit action is performed. what I need now is when the particular form entry is loaded again for editing. The fields should be populated with the data in the database before form loads. Can anyone tell me how this could be done.
I have tried using hook_validate ( ) function but the function is called when the submit action is performed which is of no use in this regard. I have to perform the database query before the form gets rendered to populate the text fields with data from tables. Kindly provide me some insight into how this could be accomplished.
I have a problem with the sql select query as well/
$query = db_select('menu_custom');
$query
->fields(array('menu_name','role1','role2','role3'))
->condition('check',1,'=')
->conditon('title',$form_state['values']['title'])
->execute();
foreach($query as $record)
{
$mname = $result ->menu_name;
$rl1 = $result -> role1;
$rl2 = $result -> role2;
$rl3 = $result -> role3;
dpm($mname." ".$rl1);
}
I am getting error that my field specification is wrong but I cant figure out the problem there.
This is a bit too long for a comment so I'll put it here:
The only error you've got in your query is that the first argument passed to the fields() function needs to be the name/alias of the table from which the fields are coming. So your query should probably look something like this:
$query = db_select('menu_custom')
->fields('menu_custom', array('menu_name','role1','role2','role3'))
->condition('check',1,'=')
->conditon('title',$form_state['values']['title'])
->execute();
You get the data from your database in your form function, and put them as default_value
$name = db_query(YOUR_SQL);
$form['first_name'] = array(
'#title' => t('First Name'),
'#type' => 'textfield',
'#default_value' => $name,
);
is this what you meant?

How to get album using example.php, facebook.php and base_facebook.php of facebook-php-sdk

in the facebook-php-sdk there is an example.php file when we can get our personal information easily doing:
$user_profile = $facebook->api('/me');
of course I get:
Array ( [data] => Array (
and all my personal data, that is ok. But when i do
$facebook->api('/me/albums');
i get:
Array ( [data] => Array
(
)
)
and nothing more. What is failing? Its curious because when I try to get my albums using:
https://developers.facebook.com/tools/explorer/?method=GET&path=me%2Falbums
it works fine.
What permissions did you accept for the access token?
You may be missing: user_photos
You can check your access token using https://developers.facebook.com/tools/debug to see what permissions is has.

Resources