How do you implement https://developers.google.com/youtube/2.0/developers_guide_protocol_deprecated using PHP?
What I tried:
<?php
$headers = array("PUT /feeds/api/users/default HTTP/1.1",
"Host: gdata.youtube.com",
"Content-Type: application/atom+xml",
"Authorization: Bearer ACCESS_TOKEN",
"X-GData-Key: key=DEVKEY",
"Content-length: ".strlen($data),
$curl = curl_init("https://gdata.youtube.com/feeds/api/users/default?v=2.1");
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_REFERER, true);
curl_setopt($curl, CURLOPT_HEADER, 0);
$returnxxx = curl_exec($curl);
curl_close($curl);
echo $returnxxx;
?>
I am missing ACCESS_TOKEN though.
Associating an unlinked Google Account with a YouTube channel is no longer possible via the APIāthat's why it's in the deprecated section of the documentation.
The current way of prompting a user to link a Google Account to a channel is described at https://developers.google.com/youtube/create-channel That guide is mobile-focused, but the same process can be kicked off by redirected a user to https://www.youtube.com/create_channel on the desktop.
Related
I am making a curl call using PHP to a PHP based URL and getting into some problems.
Please note that the when I add the Content-Type in the header, it causes the endpoint not to read my params at all.
Any help is appriciated.
Here is what I am doing and the result I am getting:
With Header but no Content-Type in Header:
$curl = curl_init();
$params="action=start_day_activity&woid=23";
$headers = [
"Authorization: Bearer $token"
];
curl_setopt($curl, CURLOPT_URL, $api_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($curl);
// Status 200
// $result becomes = "{"flag":0,"message":"Token not found in request","data":[]}"
With Header with Content-Type in Header:
*$curl = curl_init();
$params="action=start_day_activity&woid=23";
$headers = [
'Content-Type: application/json',
"Authorization: Bearer $token"
];
curl_setopt($curl, CURLOPT_URL, $api_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($curl);*
// Status 200
// $result becomes = "{"flag":0,"message":"No Request.","data":[]}"
I was using a curl request with third party pem certificate in IIS windows based server which is:
$userAgent = 'Third party name';
$headers = array(
"SOAPAction:",
"Content-Type: text/xml; charset = utf-8",
"Connection: close"
);
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_HEADER, false);
curl_setopt($cURL, CURLOPT_HTTPHEADER, $headers);
curl_setopt($cURL, CURLOPT_POST, true);
curl_setopt($cURL, CURLOPT_URL, $this->baseURL());
curl_setopt($cURL, CURLOPT_USERAGENT, $userAgent);
curl_setopt($cURL, CURLOPT_POSTFIELDS, $soap);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURL, CURLOPT_ENCODING, "UTF-8");
curl_setopt($cURL, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cURL, CURLOPT_SSLCERT, $certificateURL);
curl_setopt($cURL, CURLOPT_SSLCERTPASSWD, $this->certPass);
$response = curl_exec($cURL);
curl_close($cURL);
return $response;
the $certificateURL in windows was
$certificateURL = "C:/inetpub/wwwroot/api/kx2.pem"
and it was working fine.
Now this is shifted to a Linux server and I am using plesk for this, the cert pem file is in the same directory with code but the here is I assigned
$certificateURL to "./kx2.pem" and to "/var/www/vhosts/domain.com/httpdocs/api/kx2.pem"
it doesn't work, it gives error msg "could not load PEM client certificate, OpenSSL error error:140AB18F:SSL routines:SSL_CTX_use_certificate:ee key too small, (no key found, wrong pass phrase, or wrong file format?)" what should I do I have tried many things changed the whole curl request even tried __DIR__ based url?
I need to integrate my website with right signature for signing documents.But I couldn't figured it out because its continously showing me Invalid OAuth Request.
I'm running this api by using php library but its keep on showing Invalid OAuth Request.I'm fed up from all this. Run on Browser below url
https://RightSignature.com/api/documents.xml
You're probably trying to access a file that needs you to have api accesses. If you haven't signed up with them, then you don't have access. If you just want to see the docs, here they are.
EDIT: btw, you need to request an API Key per their docs, and you can't even view their docs until you've signed up for an account. Once you do that, they will personally approve or deny you access to keys. With that, you have about one month to do something with it.
If you have secure token use this code:
For Json response:
Method defines GET or POST,
headers contains header part,
url is rightsignature endpoints,
secure token got after registration,
Body contains parameters.
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// Append 'api-token' to Headers
curl_setopt($curl, CURLOPT_HTTPHEADER, array($headers, "api-token: $secure_token")); // Set the headers.
// If you want parameters to be sent
if ($body) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
// Append 'api-token' to Headers
curl_setopt($curl, CURLOPT_HTTPHEADER, array($headers, "Content-Type: application/javascript;charset=utf-8", "api-token: $secure_token"));
}
For XML response:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// Append 'api-token' to Headers
curl_setopt($curl, CURLOPT_HTTPHEADER, array($headers, "api-token: $secure_token")); // Set the headers.
// If you want parameters to be sent
if ($body) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
// Append 'api-token' to Headers
curl_setopt($curl, CURLOPT_HTTPHEADER, array($headers, "Content-Type: text/xml;charset=utf-8", "api-token: $secure_token"));
}
I have this code for logging into Google using Simple DOM Parser with curl. I've tried to post status on google plus using following code but unable to post on google plus
Any idea on how to solve this?
Here's my code for reference:
$clientlogin_url = "https://www.google.com/accounts/ClientLogin";
$clientlogin_post = array(
"accountType" => "HOSTED_OR_GOOGLE",
"Email" => "youremail#gmail.com",
"Passwd" => "yourpassword",
"service" => "writely",
"source" => "your application name"
);
// Initialize the curl object
$curl = curl_init($clientlogin_url);
// Set some options (some for SHTTP)
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clientlogin_post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// Execute
$response = curl_exec($curl);
// Get the Auth string and save it
preg_match("/Auth=([a-z0-9_-]+)/i", $response, $matches);
$auth = $matches[1];
$params['newcontent'] = "Post on Google Plus Test By Me";
$headers = array(
"Authorization: GoogleLogin auth=" . $auth,
"GData-Version: 3.0",
);
// Make the request
curl_setopt($curl, CURLOPT_URL, 'https://www.plus.google.com/');
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($curl);
curl_close($curl);
Thanks For your help and co-operation
There is not a Google+ API to post statuses (unless you are a Google Apps user) and ClientLogin has been deprecated and will stop working soon. You're best bet is to look into using something like the share plugin.
In order not show the moved you have to set the agent header like firefox or something else
example
curl_setopt($curl, CURLOPT_URL, 'https://www.plus.google.com/');
curl_setopt($curl,"USER_AGENT","firefox my browser");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //Added here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //Added here
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // Since you got 301 redirect
$response = curl_exec($curl);
var_dump($response);// Added here
curl_close($curl);`enter code here`
You need to add these two cURL params here too.
curl_setopt($curl, CURLOPT_URL, 'https://www.plus.google.com/');
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //Added here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //Added here
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // Since you got 301 redirect
Also, you are not outputting any response on your code
$response = curl_exec($curl);
var_dump($response);// Added here
curl_close($curl);
I will update a video with a code like this:
$headers = array("PUT /feeds/api/users/default/uploads/VIDEOID HTTP/1.1",
"Host: gdata.youtube.com",
"Authorization: GoogleLogin auth=".$authvalue,
"GData-Version: 2",
"X-GData-Key: key=KEY",
"Content-length: ".strlen($data),
"Content-Type: application/atom+xml; charset=UTF-8");
$curl = curl_init("https://gdata.youtube.com/feeds/api/users/default/uploads/VIDEOID");
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_REFERER, true);
curl_setopt($curl, CURLOPT_HEADER, 0);
$returnxxx = curl_exec($curl);
curl_close($curl);
echo $returnxxx;
I've generate a valide authvalue (tested it -> ok). But it shows:
invalid uri
Thanks for helping!
#Marc B Thanks for your hint!
I've used curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT'); instead of the curl_setopt($curl, CURLOPT_POST, 1);!