So I am using an API (SendInBlue - a transactional email service) and I am trying to use the API to display a list of the users on my webpage.
Below, SendInBlue has given me sample code to use, however when I put them together I just get a blank screen.
I know this is a total beginner question... but how do I put these 2 pieces of code together so that it actually displays the list of contacts on my website?
Thank you so much!!
EXAMPLE
require('../mailin.php');
$mailin = new Mailin("https://api.sendinblue.com/v2.0","your access key");
$data = array( "listids" => array(1,2),
"timestamp" =>"2015-05-22 14:30:00",
"page" => 1,
"page_limit" => 2
);
var_dump($mailin->display_list_users($data));
SAMPLE OUTPUT
{
"code":"success",
"message":"Retrieved details of all users for the given lists",
"data":{
"data":[
{
"blacklisted":0,
"email":"email1#domain.com",
"id":1,
"listid":[1],
"blacklisted_sms":1,
"last_modified" : "2015-05-22 15:30:00"
},
{
"blacklisted":1,
"email":"email2#domain.com",
"id":2,
"listid":[1,2],
"blacklisted_sms":0 ,
"last_modified" : "2015-05-25 19:10:30"
}
],
"page":1,
"page_limit":2,
"total_list_records":100
}
}
Ok I figured this out. I turned every attribute into a variable like so...
$subscriberemail = $getemails['data']['data'][$number]['email'];
This took ages to figure out!
Related
I've stumbled upon some problems while creating a shopping application. In short:
I'm using a php $_SESSION['cart'] to register all the products inside the cart
The products are registered and added to the cart by the following code:
else {// It's new: Add it to the array
$_SESSION['cart']['cartItems'][] = $cartProduct;
$_SESSION['cart']['totalItems']++;
}
To that function a cart with 2 or more products looks like this:
{"cartItems":[{
"id":"3",
"name":"Bedrukte Jurk",
"price":25.99,
"size":"L",
"quantity":"12",
"total_product_price":311.88
},
{
"id":"11",
"name":"Product voorraad id",
"price":144,
"size":"M",
"quantity":"23",
"total_product_price":3312
}
],
"totalPrice":3623.88,
"totalItems":2
}
So now i've got two questions regarding my $_SESSION['cart'];
How would i be able to delete a specific product. I was thinking about using the product id. And for now that has been working for me unless the unset($_SESSION['cart']['cartItems'] ... id part that i still haven't figured out. So how would i be able to tell php to delete the row with the requested id.
The second question is a bit more confusing to me since this has to do with writing the "cart" to the database on "payOrder" click.
So i've been struggling with this part and i've tried using a foreach() statement to get each row. But sadly only the first product is written in the database. The function handeling this foreach() is shown down below:
$cart_encode = json_encode($_SESSION['cart']['cartItems']);
$cartDecode = json_decode($cart_encode);
$date = date("Y-m-d h:i:s");
// Create the cart Using XML
$opt = $webService->get(array(
'resource' => 'carts',
));
// Define the $resource
$resource = $opt->children()->children();
// Adding the product items
foreach ($cartDecode as $key => $cartItem) {
$resource->associations->cart_rows->cart_row->id_product = $cartItem->{"id"};
$resource->associations->cart_rows->cart_row->id_product_attribute = 1;
$resource->associations->cart_rows->cart_row->id_address_delivery = 1;
$resource->associations->cart_rows->cart_row->quantity = $cartItem->{"quantity"};
}
Update after the comments
So as #Randall has mentioned it's better to use the product_id's as a new array index layer for deleting the row's in the cart, in this case a particulair product.
So i've edited my code to an older state in wich this is true and Question one is solved.
Anyhow the new JSON structure is:
{"cartItems": {
"5": {
"id":"5",
"name":"Bedrukte Zomerjurk",
"price":30.5,
"size":"L",
"quantity":"34",
"total_product_price":1037
},
"4": {
"id":"4",
"name":"Bedrukte Avond Jurk",
"price":50.99,
"size":"L",
"quantity":"3",
"total_product_price":152.97
}
},
"totalPrice":1189.97,
"totalItems":2
}
Still Question 2 sadly stays unanswered about the database input. I hope there are some people that could help me out.
PS: #Randall thanks for the "it makes no difference tip, it solved question 1 of the 2!".
I hope my question is clear and if it isn't please let me know.
As always,
Thanks in advance!
I'm using Google Slide API to generate presentation, and I want to create table using this API, I try this function to do it and it worked well, but it create table with "rowHeight": { "magnitude": 3000000, "unit": "EMU" },
I want to modify this value, But I didn't found how.
The G-slide API has just this fields to insert new row :
'insertTableRows'=> array(
'tableObjectId'=> $tableId,
'cellLocation'=> array(
'rowIndex'=> $rowIndex
),
'insertBelow'=> $insertBelow,
'number'=> $number
)
When I use this function I got the problem above.
OK, i need to get csgo inventory with steam API . i use this url
https://api.steampowered.com/IEconItems_730/GetPlayerItems/v1key=$api_key&steamids=$steamid
and i use this url for access to all csgo items.
https://api.steampowered.com/IEconItems_730/GetSchema/v2
problem 1, is i cant understand the returned value in first url. there is no item name, image and ... .
this is how it will return
"id": 547938992,
"original_id": 547938992,
"defindex": 13,
"level": 1,
"quality": 4,
"inventory": 53,
"quantity": 1,
"rarity": 1,
"attributes":
problem 2, when is use second url to get all of csgo skins. it just returns vanilla skins. how can i get full skins like other websites : opskins , bitskins, csgolounge and .... .
I know there is alot of question like this in Stackoverflow but none of them answer the way i can understand.
and I am sorry for my poor English.
For my project I use another url for steam's API,
"http://steamcommunity.com/profiles/*insert steamId*/inventory/json/730/2"
You can try to use your steamID and paste it into your browser and you will see how the response looks like. This is what you will be working with.
If you make a request with this url you will get a response with a json object which have two parts. One part is called rgInventory(ie. data.rgInventory)and contains ids for each skin in the users csgo-inventory. The second part is called rgDescriptions(ie. data.rgDescriptions) and contains info/name/img url for each skin. To add the info to the skins the user have in rgInventory you need to compare the classId for each item on both the rgInventoryand rgDescriptions. The classIdis the id which decide which type of weapon it is, therefore the classid is not unique.
So what Im doing is using two for-loops, and compares the ids so I can add the item_url, market_name etc. To the rgInventory array which I then I send away as the callback. Like this (javascript):
var ids = getID(data.rgInventory);
var item = getItems(data.rgDescriptions);
for (var i = 0; i < ids.length; i++) {
for (var k = 0; k < item.length; k++) {
if (ids[i].classid == item[k].classid) {
ids[i].market_name = item[k].market_name;
ids[i].icon_url = item[k].icon_url;
ids[i].tradable = item[k].tradable;
}
}
}
So if the classids of both items is the same I will add the information I want to the variable "ids" which in this case is a copy of rgInventory. When the for-loops are done I send away the ids-variable as my callback.
Feel free to ask questions, and sorry if this is confusing. Remember to type the url I linked with your steam-profile in your browser and see the result.
Hope it helps!
this is my first question to stackoverflow, so if's something wrong please advise..
Well the problem is Facebook real time updates :
I have successfully created subscription to page and it's admin user ( test page and test app created ), user has agreed permissions to manage_page, read_stream, read_friendlist, read_insights,publish_actions and a lot of user's data ( about,email etc etc )
When i query GET to Graph api with edge /subscriptions i get the result :
{
"data": [
{
"object": "user",
"callback_url": "LIVE_CALLBACK_URL",
"fields": [
"feed"
],
"active": true
},
{
"object": "page",
"callback_url": "LIVE_CALLBACK_URL",
"fields": [
"built",
"description",
"email",
"feed",
"location",
"name",
"personal_info",
"written_by"
],
"active": true
}
]
}
So, that's taken care of, after that i searched why Facebook isn't sending me any updates ( which I log to somefile.txt ) So i found out you need to query the Graph api with /tabs to create page tab for my api. When i query that it returned "success" so that's created ( can't find out where it's stored, but it working ... ).
After that i have created some data on my profile, to test and also on the page to see if the Facebook is sending any updates, and it's suddenly send one update that was comment on my user profile post ( shared on timeline ).
The response was :
14:17 05.02.2015
Array
(
[object] => user
[entry] => Array
(
[0] => Array
(
[uid] => ****my_fb_id****
[id] => ****my_fb_id - not_someone_else****
[time] => 1423146339
[changed_fields] => Array
(
[0] => feed
)
)
)
)
So Facebook send's the empty feed, and it's ok, probably some permissions or something else, but after that i have made more posts and ppl commented on it ( on user profile and test page ) but Facebook didn't send any updates, or any call to my web page.
So has anyone facing this problem in the past, and how he solved that ?
The part that is for receiving the update from Facebook is :
$method = $_SERVER['REQUEST_METHOD'];
if(isset($_GET['hub_mode']) && isset($_GET['hub_verify_token'])){
if (trim($method) == 'GET' && trim($_GET['hub_mode']) == 'subscribe' && trim($_GET['hub_verify_token']) == VERIFY_TOKEN) {
print $_GET['hub_challenge'];
}
}
else if ($method == 'POST') {
$updates = json_decode(file_get_contents("php://input"), true);
$file = 'log.txt';
$current = file_get_contents($file);
#$results = print_r($updates,true);
$current .= $results;
file_put_contents($file, $current);
}
I have tried to detail my problem as much i as could... Searched but don't really understand why it's not working.
Apart from using an outdated method as #CBroe outlined, I think you have a misunderstanding: Facebook will not send you the data that has changed, but the object (and it's fields/edges) the change occurred for User object changes.
For Pages, you can receive the changes itself (changed_fields vs. changes fields in the FB request).
See
https://developers.facebook.com/docs/graph-api/real-time-updates/v2.2#receiveupdates
Once a subscription is successfully created, Facebook will make an HTTP POST request to your callback URL every time that there are changes (to the chosen fields or edges).
That means you need to contruct a separate request from the info object you get from Facebook. In your example it would be a request to your user's feed
GET /{user_id}/feed
to query for recent changes.
I'm using facebook PHP SDK , facebook api version 2.2.
I want to display the user news feed. I'm using the following api get this.
$facebookConncetion->api("$oauthUserId/home",
'GET',
array("access_token" => $accessToken,
"limit" => '15',
"comments.limit" => 10,
"likes.limit" => 10
)
);
But it returns all the post in the user home page with 10 comment and 10 likes and it does not return summary of like and comment. How can I format this api to get the like and comment summary per post?
You have to add .summary(true) and .filter(stream) to the like and comment request just like you added the limit.
Summary will return something like this:
"comments" : {
"data" : [ ARRAY OF COMMENTS ] },
"paging" : { PAGING CURSORS/URLS }.
"summary" : {
"total_count" : NUMBER OF COMMENTS
}
},
Adding .filter(stream) will return ALL comments/likes. With out this there may be some missing due to Facebook filtering them out due to their low "story" value. It will also order all comments/likes in true chronological order.
https://developers.facebook.com/docs/graph-api/reference/v2.2/object/comments
Look under "Modifiers" works with both comments and likes.