I'm using Facebooks Webhooks for lead generations. I successfully can fetch leadgen_id from the Facebooks callback.
So this is what Facebook returns for the leadgen field:
Array
(
[entry] => Array
(
[0] => Array
(
[changes] => Array
(
[0] => Array
(
[field] => leadgen
[value] => Array
(
[ad_id] => 0
[form_id] => 1109138149146076
[leadgen_id] => 1109157429144148
[created_time] => 1467887375
[page_id] => 152161181508654
[adgroup_id] => 0
)
)
)
[id] => 152161181508654
[time] => 1467887376
)
)
[object] => page
)
Is it possible to somehow get campaign ID from these values that Facebook returns?
There is no clue to campaign in leadgen itself and in the form that I fetched with leadgen_id and form_id.
I also tried to fetch all ad account campaigns with
/v2.6/<ad_account_id>/campaigns
endpoint and thought that I will see some connection there with form or leadgen, but nothing there as well.
So, I need to fetch it so that I can group leadgen forms in Facebook. With current implementation, unfortunately it is not possible - I guess Facebook didn't thought of that :(
Just in case someone will struggle with this as well:
We can grab ad id info from:
'https://graph.facebook.com/v2.6/<AD_ID>?access_token=<ACCESS_TOKEN>&fields=campaign_id';
And this will return us campaign id.
Reason why I didn't try this in first place, was because in initial response, Facebook returned ad_id as 0, but after some while I realised that this is probably because it was a test lead from https://developers.facebook.com/tools/lead-ads-testing
Related
I am having an issue trying to build an array where the status ID is the key and ALL posts related to the statuses are sub-arrays relating to the key (status ID).
Here's the (incorrect) array I am getting with both array_merge_recursive and manually adding items to the array (array 1):
Array
(
[res_1] => Array
(
[status_name] => NEEDS REVIEW
[status_color] => 666666
[post] => Array
(
[post_title] => Add feature that allows our team to add internal notes on ideas
[post_description] => Sometimes our team needs to leave feedback that users should not see publicly. Having this feature would allow the team to collaborate better at scale.
[categories] => Admin,Communication
)
)
[res_2] => Array
(
[status_name] => PLANNED
[status_color] => aa5c9e
[post] => Array
(
[post_title] => Add support for multiple languages
[post_description] => We have customers across the globe who would appreciate this page to be localized to their language
[categories] => Integrations
)
)
[res_3] => Array
(
[status_name] => IN PROGRESS
[status_color] => 3333cc
[post] => Array
(
[post_title] => Allow users to add an image with their feature request
[post_description] => Sometimes users want something visual, having an example really helps.
[categories] => Uncategorized
)
)
[res_4] => Array
(
[status_name] => COMPLETED
[status_color] => 7ac01d
[post] => Array
(
[post_title] => Add feature that allows #mentioning in comments
[post_description] => There is no hierarchy in comments so it's hard to reply to one specific user if there is a longer thread of comments.
[categories] => Communication
)
)
)
Here's something like what I am expecting to happen (every status ID is an array with multiple posts as sub-arrays):
Array
(
[res_1] => Array
(
[status_name] => NEEDS REVIEW
[status_color] => 666666
[post] => Array
(
[post_title] => Add feature that allows our team to add internal notes on ideas
[post_description] => Sometimes our team needs to leave feedback that users should not see publicly. Having this feature would allow the team to collaborate better at scale.
[categories] => Admin,Communication
)
)
[res_2] => Array
(
[status_name] => PLANNED
[status_color] => aa5c9e
[post] => Array
(
[post_title] => Add support for multiple languages
[post_description] => We have customers across the globe who would appreciate this page to be localized to their language
[categories] => Integrations
)
)
[res_3] => Array
(
[status_name] => IN PROGRESS
[status_color] => 3333cc
[post] => Array
(
[post_title] => Allow users to add an image with their feature request
[post_description] => Sometimes users want something visual, having an example really helps.
[categories] => Uncategorized
)
)
[res_4] => Array
(
[status_name] => COMPLETED
[status_color] => 7ac01d
[post] => Array(
[0] => Array (
[post_title] => Add feature that allows #mentioning in comments
[post_description] => There is no hierarchy in comments so its hard to reply to one specific user if there is a longer thread of comments.
[categories] => Communication
)
[1] => Array (
[post_title] => Feature Number 5
[post_description] => lorum ipsum awesomeness.
[categories] => Admin
)
)
)
Here's what I've tried:
Running two separate DB queries: one to fetch statuses and another to fetch posts then merging the arrays recursively and changing the array keys to a string. This does the same thing, post 5 never shows up in the newly merged array.
Same as above - ran two separate queries and rebuilt the array manually, the same result the 5th post never appears.
I printed out the database result from $stmt2->fetchAll(); all 5 posts are there in the result-set directly from the database. The 5th one just won't persist when merging arrays or building a fresh one so the posts can relate to the statuses.
I also tried joining the tables with SQL but even grouping by resolution_id does the same thing, post number 5 gets lost by the grouping. I've tried sub-queries too.
DB Results array for just posts:
Array
(
[0] => Array
(
[title] => Feature number 5
[0] => Feature number 5
[description] => lorum ipsum awesomeness
[1] => lorum ipsum awesomeness
[resolution_id] => 4
[2] => 4
[category_names] => Admin
[3] => Admin
)
[1] => Array
(
[title] => Allow users to add an image with their feature request
[0] => Allow users to add an image with their feature request
[description] => Sometimes users want something visual, having an example really helps.
[1] => Sometimes users want something visual, having an example really helps.
[resolution_id] => 3
[2] => 3
[category_names] => Uncategorized
[3] => Uncategorized
)
[2] => Array
(
[title] => Add support for multiple languages
[0] => Add support for multiple languages
[description] => We have customers across the globe who would appreciate this page to be localized to their language
[1] => We have customers across the globe who would appreciate this page to be localized to their language
[resolution_id] => 2
[2] => 2
[category_names] => Integrations
[3] => Integrations
)
[3] => Array
(
[title] => Add feature that allows #mentioning in comments
[0] => Add feature that allows #mentioning in comments
[description] => There is no hierarchy in comments so it's hard to reply to one specific user if there is a longer thread of comments.
[1] => There is no hierarchy in comments so it's hard to reply to one specific user if there is a longer thread of comments.
[resolution_id] => 4
[2] => 4
[category_names] => Communication
[3] => Communication
)
[4] => Array
(
[title] => Add feature that allows our team to add internal notes on ideas
[0] => Add feature that allows our team to add internal notes on ideas
[description] => Sometimes our team needs to leave feedback that users should not see publicly. Having this feature would allow the team to collaborate better at scale.
[1] => Sometimes our team needs to leave feedback that users should not see publicly. Having this feature would allow the team to collaborate better at scale.
[resolution_id] => 1
[2] => 1
[category_names] => Admin,Communication
[3] => Admin,Communication
)
)
Since the data is always going to be dynamic (users can choose status names and create as many as they need to) I can't just hard-code the status names/ids and run 4 queries to populate the columns.
To prevent this from being an essay long post, here are the bits of code that are building the array from array 1:
Builds the initial statuses array from the query results from the resolutions table.
$statuses = [];
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$statuses['res_' . $row['id']] = ['status_name' => $row['name'], 'status_color' => $row['color']];
}
Adds the individual posts to the statuses array:
foreach ($dbposts as $row2) {
$statuses['res_' . $row2['resolution_id']]['post'] = ['post_title' => $row2['title'], 'post_description' => $row2['description'], 'categories' => $row2['category_names']];
}
The resolution ID is concatenated with res_ from when I tried doing an array merge based on keys. It would not merge when the keys were just integers.
Finally some context behind why I am trying to do what I am trying to do. I am building a platform where companies can have users submit feature requests and view the results in a list view or board view. The list view was a piece of cake since the board view needs to be per status, this is where I am having trouble. I hard-coded the board view values to demonstrate the expected end-result:
Not looking for someone to write my code for me, just looking for some guidance - perhaps I am building or merging the arrays wrong?
To build the array of posts, you need to append elements to the array of posts. Currently, you are just assigning a single element to the array over and over, which overwrites the previous value of the entire array.
The code to append posts:
$statuses['res_' . $row2['resolution_id']]['post'][] = ['post_title' => $row2['title'], 'post_description' => $row2['description'], 'categories' => $row2['category_names']];
Note the [] which I added to the end of the left side of the assignment operator.
I'm trying out IBM Watson Assistant. Ultimate goal is to integrate it with my custom PHP backend, via it's Watson Assistant's cURL API Endpoints (because there's no complete PHP SDK yet).
When I setup a Dialog with the OPTIONS (other than, TEXT) as the Respond, the OPTIONS are perfectly working inside it's own "Try it out" Chat Window. But when I query it through the cURL API as usual, everything else is working except for that Dialogs with OPTIONS.
Here's the working example inside Try it out Window:
But then, here's the return from cURL API (for the same question asked):
stdClass Object
(
[intents] => Array
(
[0] => stdClass Object
(
[intent] => SOexchangenetworks
[confidence] => 1
)
)
[entities] => Array
(
)
[input] => stdClass Object
(
[text] => Which Stack Exchange Network should I go to look for an answer?
)
[output] => stdClass Object
(
[text] => Array
(
)
[nodes_visited] => Array
(
[0] => node_1_1531885028865
)
[log_messages] => Array
(
)
)
[context] => stdClass Object
(
[conversation_id] => 77ec8fc6-fb6a-4890-92b4-c58cdbc85ba3
[system] => stdClass Object
(
[dialog_stack] => Array
(
[0] => stdClass Object
(
[dialog_node] => root
)
)
[dialog_turn_counter] => 1
[dialog_request_counter] => 1
[branch_exited] => 1
[branch_exited_reason] => completed
)
)
)
Problem Highlight:
You can see that [output][text] section is totally blank, when the Dialog Respond contains OPTIONS.
Note: Normally, the [output][text] section contains the reply from Watson, if the Respond type is Text. I've been keep using this cURL API for a while.
How do I solve this please?
Based on the Watson Assistant release notes so called "rich responses" were added July 2018. The current API version is 2018-07-10. In your curl command you are using the API version 2018-02-16. Try the curl command again, but we the current API version.
I'm trying to get the list of users that are checked in a venue.
using following url (php):
$url = 'https://api.foursquare.com/v2/venues/5576e64f498e907e749435d4/herenow?client_id=' . $fsClientId
. '&oauth_token=' . $_SESSION['foursquareToken']->access_token . '&v=20130815';
If i'm checked in to the same venue I get a list of people who are checked in to the venue. If i'm not checked in there's an empty "items" object(I've json_decoded it to an object):
stdClass Object ( [meta] => stdClass Object ( [code] => 200 ) [notifications] => Array ( [0] => stdClass Object ( [type] => notificationTray [item] => stdClass Object ( [unreadCount] => 0 ) ) ) [response] => stdClass Object ( [hereNow] => stdClass Object ( [count] => 1 [items] => Array ( ) ) ) )
Is it possible to list people checked in to a venue without being checked in to it yourself?
I've read somewhere you have to be venue-owner for this being able to work. Is that correct?
How does one become venue-owner in that case?
Or is it truely not possible at all?
Thanks in advance.
MackDoms
Is it possible to list people checked in to a venue without being checked in to it yourself?
Yes, it is possible. You do not need to check in there. However, a list that you can see, the only friends of your friends or friends.
https://developer.foursquare.com/docs/venues/herenow
Returns a list of friends and friends-of-friends at the venue for authenticated requests. If the acting user is currently checked in to the venue, then a list of other users is also returned.
I am using SugarCRM Pro 6.5.5. I am trying to do some integration into another application, so I need to do some API calls from that other application. I am using the REST API v2. At this point, I need to get a Contact that is related to an Account via the account ID. I have tried both get_relationships() and get_entry_list(), but I can't get either of them to work.
Here's my input for get_relationships():
{"session":"eujfbfsfjgni98m0mivl6jm6r2","module_name":"Accounts","module_id":"c03d0649-0525-2f90-1206-50881e87d7dd","link_field_name":"contacts"}
I have tried many variations of this, and several other options, but nothing did what I wanted. This is the output from above:
stdClass Object
(
[entry_list] => Array
(
[0] => stdClass Object
(
[id] =>
[module_name] => Contacts
[name_value_list] => stdClass Object
(
[deleted] => stdClass Object
(
[name] => deleted
[value] => 0
)
[do_not_call] => stdClass Object
(
[name] => do_not_call
[value] => 0
)
)
)
)
[relationship_list] => Array
(
)
)
I don't see how this information could ever be useful.
Next up, I tried get_entry_list() with a query to select only the Contacts that had the given account ID. Here's my input for that:
{"session":"8mol33e7kdq6girugu30dnt074","module_name":"Contacts","query":"accounts.id = 'c03d0649-0525-2f90-1206-50881e87d7dd'"}
I am using accounts.id because I have read in similar questions, that is correct. I've tried many other things, like: contacts.account_id, account_id, etc. In every case, I get a MySQL error in the log stating the column is invalid.
SugarCRM: how to get all contacts for an account via REST API
This question is relevant, and seems to be the exact same problem. I tried adding a link_name_to_fields_array option to my input, but no matter what value I provide, it results in the following MySQL error in the log:
AND jt11.deleted=0 where (Array) AND contacts.deleted=0: MySQL error 1054: Unknown column 'Array' in 'where clause'
Dafuq?
Thanks.
Thanks to ychaouche, I figured it out.
I was able to use the get_relationships() method after all. I had tried before adding the related_fields to my input, but all that did was result in an empty result set. The answer? Set related_module_query to an empty string... and now the result set is not empty. Yep, my 3+ hours of furious Googleing last night is because of that.
So, here is some working code in case anyone else has this problem:
{
"session": "iov9pg9kvvl60librung1h5fh6",
"module_name": "Accounts",
"module_id": "c03d0649-0525-2f90-1206-50881e87d7dd",
"link_field_name": "contacts",
"related_module_query": "",
"related_fields": [
"first_name",
"last_name"
],
"deleted": false
}
This got me the following result set:
stdClass Object
(
[entry_list] => Array
(
[0] => stdClass Object
(
[id] =>
[module_name] => Contacts
[name_value_list] => stdClass Object
(
[first_name] => stdClass Object
(
[name] => first_name
[value] => John
)
[last_name] => stdClass Object
(
[name] => last_name
[value] => Smith
)
)
)
)
[relationship_list] => Array
(
)
)
You can of course specify different fields in related_fields and get different pieces of data.
Take a look at sugarcrm/tests/service/RESTAPI4Test.php. It's got plenty of examples on how to use the REST API. It's a common practice to look at test code for code examples on how to use a library/framework/API. Tests are in this sense a very good documentation.
Hope that helps.
Let me be up front: I'm a PHP hack. There's probably some stupid mistakes in here. Please point them out if you see them.
What I'm trying to do: I'm creating a page for a restaurant that would like their Yelp reviews displayed. I'm using the Yelp Phone API to grab the reviews for the specific business. Please view the sample response on the Yelp API documentation located here: http://www.yelp.com/developers/documentation/phone_api#sampleResponse
What I've done:
Successfully connected to the API and returned a response
echoed values from the response array in a foreach loop.
If you view the documentation, you can see there are a few levels of the response. I can easily print, echo, whatever values from the second tier, but what I'm really after is all nested in the "reviews" section of the response. I'm having trouble figuring out how to echo the values within the reviews section (eg user_name, review_excerpt etc).
My Code:
$yelpstring = file_get_contents("http://api.yelp.com/phone_search?phone=[redactedphonenumber]&ywsid=[redactedapikey]", true);
$obj = json_decode($yelpstring);
foreach($obj->businesses as $key => $business)
{
$reviews = $business->reviews;
//print_r($reviews);
echo $reviews['user_name'];
}
If I echo $reviews, I just get the word "Array". If I print_r($reviews), I get an expected list of keys and values. If I try to echo a specific value from the array(echo $reviews['user_name'], I get nothing. Any light shed on what I'm doing wrong would be greatly appreciated. I'm sure I'm missing something simple. Thank you for your time!
Edit: print_r($reviews) output:
Array ( [0] => stdClass Object ( [rating_img_url_small] => http://media4.px.yelpcdn.com/static/201012164278297776/img/ico/stars/stars_small_2.png [user_photo_url_small] => http://media2.px.yelpcdn.com/static/201012162819681786/img/gfx/blank_user_extra_small.gif [rating_img_url] => http://media4.px.yelpcdn.com/static/201012163489049252/img/ico/stars/stars_2.png [rating] => 2 [user_url] => http://www.yelp.com/user_details?userid=vZbcPrYPSMFIDIfTub5H1g [url] => http://www.yelp.com/biz/jelly-cafe-denver#hrid:u9ckRV6tKApe6Bu93M93CA [mobile_uri] => http://m.yelp.com/biz/5G2X2q9p7QFdm-LbyutltQ?srid=u9ckRV6tKApe6Bu93M93CA [text_excerpt] => I wanted to like this place. It's got the contemporary name and it's full of hipsters. The place looked clean and the style was fun and cute. I felt like... [user_photo_url] => http://media3.px.yelpcdn.com/static/201012161186834854/img/gfx/blank_user_small.gif [date] => 2011-09-07 [user_name] => boycott p. [id] => u9ckRV6tKApe6Bu93M93CA ) [1] => stdClass Object ( [rating_img_url_small] => http://media4.px.yelpcdn.com/static/201012164278297776/img/ico/stars/stars_small_2.png [user_photo_url_small] => http://media1.px.yelpcdn.com/upthumb/MWu84G5QtmBmT9GoqjT_kg/ss [rating_img_url] => http://media4.px.yelpcdn.com/static/201012163489049252/img/ico/stars/stars_2.png [rating] => 2 [user_url] => http://www.yelp.com/user_details?userid=izF2cGrmqt-u_Z2tDZ8dbg [url] => http://www.yelp.com/biz/jelly-cafe-denver#hrid:OYLeeCMgnpZkk1c9LWu97g [mobile_uri] => http://m.yelp.com/biz/5G2X2q9p7QFdm-LbyutltQ?srid=OYLeeCMgnpZkk1c9LWu97g [text_excerpt] => Food is decent and overpriced, but service is a joke. Your food will take a minimum of 20 minutes, for the basic breakfast. Then when your food does come... [user_photo_url] => http://media1.px.yelpcdn.com/upthumb/MWu84G5QtmBmT9GoqjT_kg/ms [date] => 2011-09-06 [user_name] => April H. [id] => OYLeeCMgnpZkk1c9LWu97g ) [2] => stdClass Object ( [rating_img_url_small] => http://media2.px.yelpcdn.com/static/20101216418129184/img/ico/stars/stars_small_4.png [user_photo_url_small] => http://media1.px.yelpcdn.com/upthumb/3euzdGdLZRFxImY68MSg7w/ss [rating_img_url] => http://media2.px.yelpcdn.com/static/201012164084228337/img/ico/stars/stars_4.png [rating] => 4 [user_url] => http://www.yelp.com/user_details?userid=bHR9UU4vtx2QKZD44O0E5g [url] => http://www.yelp.com/biz/jelly-cafe-denver#hrid:njvNAzfSII3PxXyUymLZ1w [mobile_uri] => http://m.yelp.com/biz/5G2X2q9p7QFdm-LbyutltQ?srid=njvNAzfSII3PxXyUymLZ1w [text_excerpt] => Stopped here for breakfast on a friday morning. We were seated immediately and had a really friendly waitress. I ordered a side order of the Chai french... [user_photo_url] => http://media1.px.yelpcdn.com/upthumb/3euzdGdLZRFxImY68MSg7w/ms [date] => 2011-09-05 [user_name] => Diane F. [id] => njvNAzfSII3PxXyUymLZ1w ) )
Based on the output of print_r you can't reference $reviews['user_name'];
Note that $reviews is an Array of objects. So to access user_name you need to use
echo $reviews[0]->user_name;
And if you have more than one item in the array, you will need a loop like
for ($i = 0; $i<count($reviews); $i++) {
echo $reviews[$i]->user_name;
}
I hope this helps.
$reviews is an array of review objects. You'll need to loop over it to get to the data you're after.