How to use Deep link of urban airship using PHP - php

I am trying to send push notification using deep link parameters but unfortunately it is not working for me. I'm using PHP and curl and my code is:
$params = array("audience"=> "all", "notification" => array("alert" => "Push notification from PHP", "actions" => array("app_defined" => array("^+t" => "sec:147", "content" => "http://www.url.com"))), "device_types" => array("android"));
$x = executeCurl('/push/', 'POST', $params);
print_r($x);
Actually I want to parse these params to my PHP code.
Can someone suggest me what I'm doing wrong with these parameters? I want to use all params of pic in my PHP code.

Finally done and parameter look likes:
$params = array(
"audience"=> "all",
"notification" => array(
"alert" => "Test msg from PHP with deep linking",
"actions" => array(
"open" => array(
"type" => "deep_link",
"content" => "your-schema://deeplink/sec/147/det/1245-15454-dfkjd-45554",
)
)
),
"device_types" => array(
"android", "ios")
);
$x = executeCurl('/push/', 'POST', $params);
print_r($x);

Related

Empty Payload. JSON content expected (guzzle, php, azur active directory and outlook)

I am a student in programming and I have difficulties with my projects, little documentation meets my expectations and I would need help.
in this project I have to send from my application the token, the json flow on outlook to schedule a meeting
about Project : the principle is on a page to create a meeting which will then be linked to the outlook calendar this document helped me a lot https://learn.microsoft.com/fr-fr/graph/api/calendar-post-events?view=graph-rest-1.0&tabs=http https://youtu.be/orVsKsRs2Us
(data is on another page)
the whole function
public function Postcalendrier($ID,$data) {
$token=$_SESSION['token'];
$ID=$_SESSION["ID"];
$calendarGroup="/calendarGroups/{myID}/";
$calendar="calendars/{myID}/events";
$urlcalendar="https://graph.microsoft.com/v1.0/users/".$ID;
$url=$urlcalendar.$calendarGroup.$calendar;
$headers = [
'Authorization' => 'Bearer '.$token->access_token,
'Accept' => 'application/json',
'Content-Type' => 'application/json',
];
$json = json_encode([$data])
$reponse = $this->guzzle->request('POST', $url,['headers' =>
$headers,'json' => $json],['debug' => true]);
return $response->getStatusCode();
}
$data = array(
"subject" => $Subject,
"body" => array(
"contentType" => "HTML",
"content" => $Content
),
"start" => array(
"dateTime" => $StartDateTime."T".$StartHourTime.":00",
"timeZone" => "$localDatetime"
),
"end" => array(
"dateTime" => $StartDateTime."T".$EndHourTime.":00",
"timeZone" => "$localDatetime"
),
"location" => array(
"displayName" => $Location
),
"attendees"=> [array(
"emailAddress"=> array(
"address"=> $addressmail,
"name"=>$prenom
),
"type"=> "required"
)]
);
I get this error message
Empty Payload. JSON content expected
so I tried with a different JSON but
I got this message instead and I don't really understand it
code UnableToDeserializePostBody message were unable to deserialize
this is my new json
$json = [
'json' => json_encode([$data])
];
thank you for your attention

Update video using youtube api

I want to update a video using google api v3 and i get the error 400 Bad Request.
This is my code.
$url = 'https://www.googleapis.com/youtube/v3/videos?part=snippet&videoId='.$_GET['videoId'].'&access_token='.Session::get('access_token');
$params = array(
"id"=> $_GET['videoId'],
"kind"=> "youtube#video",
'snippet' => array(
"title"=> "I'm being changed.",
"categoryId"=> "10",
"tags"=> array(
"humanities",
"Harpham",
"BYU"
),
'description' => 'test!'
)
);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'PUT',
'content' => http_build_query($params),
),
);
$context = stream_context_create($options);
$result = json_decode(file_get_contents($url, false, $context));
I think since you don't set all parameters inside snippet, that's giving an error. What you can do is, first getting that video with videos->list, then updating the field you are interested in and sending back the update request with the whole object back.
Here's an example also utilizing php client library: https://github.com/youtube/api-samples/blob/master/php/update_video.php

PHP how to create JSON with localization arguments for APNS

I want to send JSON in an APNS with the following:
{
"aps" : {
"alert" : {
"loc-key" : "GAME_PLAY_REQUEST_FORMAT",
"loc-args" : [ "Jenna", "Frank"]
},
"sound" : "default"
},
}
Can anyone explaine how I can create this in PHP?
I have the following for JSON without the key/args:
$body['aps'] = array(
'alert ' => 'This is my messsage',
'sound' => 'default'
);
$payload = json_encode($body);
I have tried to replace the 'This is my message' with an array for loc-key and loc-args but that does not work. Also jus putting in the data as string does not work..
Hope someone can help me. I have tried multiple options and variations but nothing works..
$body = array(
"aps" => array(
"alert" => array(
"loc-key" => "GAME_PLAY_REQUEST_FORMAT",
"loc-args" => array( "Jenna", "Frank" )
),
"sound" => "default",
),
);
echo json_encode($body);
$body['aps']['alert'] = array(
"loc-key" => "GAME_PLAY_REQUEST_FORMAT",
"loc-args" => array("Jenna", "Frank")
);
just replace the content

Retrieving JSON response using HTTPful library for Laravel

I am currently building a e-mail client (inbound and outbound sending) using Mandrill as the e-mail sending / inbound service and Laravel 3.x.
In order to send messages, I am using the HTTPful bundle with the Mandrill using the following code in my mail/compose POST method.
$url = 'https://mandrillapp.com/api/1.0/messages/send.json';
$data = array(
'key' => '{removedAPIkey}',
'message' => array (
'to' => array( array( "email" => $_to ) ),
'from_name' => Auth::user()->name,
'from_email' => Auth::user()->email,
'subject' => $_subject,
'html' => $_body
),
'async' => true
);
$request = Httpful::post($url)->sendsJson()->body($data)->send();
Link to better formatted code above: http://paste.laravel.com/m79
Now as far as I can tell from the API log, the request is correctly made (with the expected JSON) and a response of the following format is sent back:
[
{
"email": "test#test.com",
"status": "queued",
"_id": "longmessageID"
}
]
However, what I am trying to do is access the response from the request (specifically the _id attribute), which is in JSON. Now as far as I'm aware, the HTTPful class should do this automatically (using json_decode()). However, accessing:
$request->_id;
is not working and I'm not entirely sure how to get this data out (it is required so I can record this for soft-bounce, hard-bounce and rejection messages for postmaster-like functionality)
Any assistance would be appreciated.
Edit
Using the following code, results in the mail being sent but an error returned:
$url = 'https://mandrillapp.com/api/1.0/messages/send.json';
$data = array(
'key' => '{removedAPIkey}',
'message' => array (
'to' => array( array( "email" => $_to ) ),
'from_name' => Auth::user()->name,
'from_email' => Auth::user()->email,
'subject' => $_subject,
'html' => $_body
),
'async' => true
);
$request = Httpful::post($url)->sendsJson()->body($data)->send();
if ( $request[0]->status == "queued" ) {
$success = true;
}
Results in an exception being thrown: Cannot use object of type Httpful\Response as array
I must say, a huge thanks to Aiias for his assistance. I managed to fix this myself (I must have spent hours looking at this). For anyone who wants to know, the HTTPful bundle has a body array, where the response is kept. Therefore, the code below works:
$url = 'https://mandrillapp.com/api/1.0/messages/send.json';
$data = array(
'key' => '{removedAPIkey}',
'message' => array (
'to' => array( array( "email" => $_to ) ),
'from_name' => Auth::user()->name,
'from_email' => Auth::user()->email,
'subject' => $_subject,
'html' => $_body
),
'async' => true
);
$request = Httpful::post($url)->sendsJson()->body($data)->send();
if ( $request->body[0]->status == "queued" ) {
$success = true;
}
Again, huge thanks to Aiias for clearing some major confusion up for me!

SugarmCRM REST API always returns "null"

I'm trying to test out the SugarCRM REST API, running latest version of CE (6.0.1). It seems that whenever I do a query, the API returns "null", nothing else. If I omit the parameters, then the API returns the API description (which the documentation says it should).
I'm trying to perform a login, passing as parameter the method (login), input_type and response_type (json) and rest_data (JSON encoded parameters). The following code does the query:
$api_target = "http://example.com/sugarcrm/service/v2/rest.php";
$parameters = json_encode(array(
"user_auth" => array(
"user_name" => "admin",
"password" => md5("adminpassword"),
),
"application_name" => "Test",
"name_value_list" => array(),
));
$postData = http_build_query(array(
"method" => "login",
"input_type" => "json",
"response_type" => "json",
"rest_data" => $parameters
));
echo $parameters . "\n";
echo $postData . "\n";
echo file_get_contents($api_target, false,
stream_context_create(array(
"http" => array(
"method" => "POST",
"header" => "Content-Type: application/x-www-form-urlencoded\r\n",
"content" => $postData
)
))) . "\n";
I've tried different variations of parameters and using username instead of user_name, and all provide the same result, just a response "null" and that's it.
Try setting input_type and response_type to JSON (capitals). If it doesn't work, go to Sugar installation, edit config.php entry under logger => level and make it debug instead of fatal and see if it says about any errors.

Categories