I want to create a google calendar using php api, is it possible ?
Thanks for your help.
Yes it is possible !
$url = 'http://www.googleapis.com/calendar/v3/calendars';
$data = array(
'summary' => 'MyNewCalendarTitle'
);
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);
code from this page
link to doc for Calendar Insert
But it's way easier to use the Google API PHP client library
$calendar = new Calendar();
$calendar->setSummary('calendarSummary');
$calendar->setTimeZone('America/Los_Angeles');
$createdCalendar = $service->calendars->insert($calendar)
Refer this URL, it will help you
https://developers.google.com/google-apps/calendar/v1/developers_guide_php
https://developers.google.com/google-apps/calendar/
http://www.sanisoft.com/blog/2010/04/26/howto-google-calendar-api-php/
http://googleappsdeveloper.blogspot.in/2010/09/new-json-format-for-google-calendar-api.html
http://mark.biek.org/blog/2010/07/addingdeleting-events-with-the-google-calendar-api/
http://www.phpclasses.org/package/7420-PHP-Generate-links-to-add-events-to-Google-Calendar.html6
Related
Is there an easy way to send out push notifications in PHP without using external libraries? Here is my current code. when executed the server gives a 400 UnauthorizedRegistration error. I do not care about how fast or efficient the process is, I am fine with sending one notification at a time.
My PHP code is:
<?php
ini_set("display_errors","1");
$endpoint = "https://fcm.googleapis.com/fcm/send/fImmyvrGiSo:APA91bFg8A4N4GLmJMhouxPfw_R3ocv44uBaNkZu_JMVjAvueISJUJTQROpVxlBnX8PIeJGwE5s1pvLAldtcW-z6WzZ0Ixus2fc3jUADGbJ2L8kAdMv56S5cSmKMsFmPwDsdd2MoCrHC";
$postdata = http_build_query(
array(
"p256dh" => "BAHBGTIPl7M1v8Ui7EaNVlauLmi_jEJOreCQ3YTRu_nWgF4k8nwP5rewGWO86-3wP8yZ86GoKjHQpK_0sls05FI=",
"auth" => "V08681gA2Gs_2x_UNFCN0g=="
)
);
$opts = array('http' =>
array(
'ignore_errors' => true,
'method' => 'POST',
'header' => 'Content-type: application/json',
'content' => $postdata
)
);
$context = stream_context_create($opts);
// here file_get_contents is used to send a POST request
$result = file_get_contents($endpoint, false, $context);
echo $result;
?>
My push subscription is:
{"endpoint":"https://fcm.googleapis.com/fcm/send/dcgCC59wHCE:APA91bHEzFoal6MXgXWt16aSdGHFAeS7D4vre99pCvzU_QWK22YFkmYdUQ5OmiLmUUbuhyiFEDHg61TrpllZ-TcaSgqXXOIcyTUf_0I-ngZ--aH2OFnEIrB2eI-ZRiArHD5LVAAz1EiM","expirationTime":null,"keys":{"p256dh":"BAHBGTIPl7M1v8Ui7EaNVlauLmi_jEJOreCQ3YTRu_nWgF4k8nwP5rewGWO86-3wP8yZ86GoKjHQpK_0sls05FI=","auth":"V08681gA2Gs_2x_UNFCN0g=="}}
I'm trying to send a special character, such as ñ, through a POST request in PHP. When I do it, it comes out as ñ, what is wrong and how do I fix it?
I'm sending and receiving the post request in PHP, here is what I use to send it:
$url = '<url>';
$data = array('key' => 'ñ');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo $result;
Thanks in advance!
Try using this:
$data = array('key' => urlencode('ñ'));
And in the $url file:
$_POST['key']=urldecode($_POST['key']);
This is how I use to send special characters in GET and POST method with ajax, it must work for php too.
I've been looking for a solution for such a long time for my issue.
But i just can't find any solutions and i'm not sure what exactly to search for.
I'll explain my problem here.
Currently i have this PHP script which works perfect and sends a successfully request and receives the respond.
<?php
$url = 'http://example.nl/index.php';
$data = array('url' => 'http://www.myip.nl/', 'verkort' => 'Verkort URL');
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);
?>
But i really need help with sending a request with the following content:
See screenshot: http://i.imgur.com/VgedJes.png
I need to add the 3 headers and i'm not sure how to tell a field/value is empty as you can see in the screenshot.
I just can't figure out how to do this.
I would really appreciate it if someone could help me out with this!
To Add Header :
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\nX-Requested-With: XmlHttpRequest",
'method' => 'POST',
'content' => http_build_query($data),
),
);
Keep in mind that X-Requested-Header can only be interpreted by your PHP application
To send a parameter with an empty value you can do as follow
$data = array('url' => 'http://www.myip.nl/', 'verkort' => 'Verkort URL', 'notMandatoryParam' => '');
Also in your PHP code, you must do a verification : if(empty($_POST['notMandatoryParam'])) {/*SKIP ME*/}
I want to update my twitter status using the Twitter API. Here is my code:
$access_token = "{Twitter Access Token}";
$access_secret = "{Twitter Access Token Secret}";
$send_url = "https://api.twitter.com/1.1/statuses/update.json";
$opts = array('http' => array(
'method' => 'POST',
'header' => "Content-type: application/x-www-form-urlencoded&oauth_token=$access_token&oauth_token_secret=$access_secret",
'content' => 'status=Hello'
) );
$context = stream_context_create($opts);
$result = file_get_contents($send_url, false, $context);
echo $result;
What am I doing wrong? Am I sending through the oAuth tokens correctly?
Any help would be much appreciated.
Hi I'm trying to send post values using a PHP script to an external website and get the result. My code is as follows
$postdata = http_build_query(
array(
'drpservice' => 091,
'drpdirection' => 1,
'drpbusstop' => 18051
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
echo $result;
However, it won't return the required results unless I can manage to send in the hidden _VIEWSTATE value.
Anyone able to help?
You need to first get the form page using a GET request, and then you can parse the page to get the _VIEWSTATE value using a regular expression.
Then when doing the POST pass the value you got for it.