DailyMotion Invalid authorization code - php

I'm trying to send videos by DailyMotion PHP SDK with this code:
<?php
require_once 'dailymotion-sdk-php-master/Dailymotion.php';
$api = new Dailymotion();
$api->setGrantType(Dailymotion::GRANT_TYPE_AUTHORIZATION, '081cf3f9d3f64c8d9234', '98da6430d6ebef2621f1061886ecde1a0aa57def', array('manage_videos'));
try
{
$url = $api->uploadFile('video.avi');
$result = $api->call('video.create', array('url' => $url));
}
catch (DailymotionAuthRequiredException $e)
{
// Redirect the user to the Dailymotion authorization page
header('Location: ' . $api->getAuthorizationUrl());
return;
}
catch (DailymotionAuthRefusedException $e)
{
// Handle case when user refused to authorize
// <YOUR CODE>
}
?>
I always get the following error:
Fatal error: Uncaught exception 'DailymotionAuthException' with message 'Invalid authorization code.' in /folder/public_html/dailymotion-sdk-php-master/Dailymotion.php:541 Stack trace:
#0 /folder/public_html/dailymotion-sdk-php-master/Dailymotion.php(370): Dailymotion->oauthTokenRequest(Array)
#1 /folder/public_html/dailymotion-sdk-php-master/Dailymotion.php(247): Dailymotion->getAccessToken()
#2 /folder/public_html/dailymotion-sdk-php-master/Dailymotion.php(203): Dailymotion->call('GET /file/uploa...', Array)
#3 /folder/public_html/dailymotion-sdk-php-master/Dailymotion.php(189): Dailymotion->get('/file/upload')
#4 /folder/public_html/index.php(9): Dailymotion->uploadFile('video.avi')
#5 {main} thrown in /folder/public_html/dailymotion-sdk-php-master/Dailymotion.php on line 541
I've tried the JLepage suggestion( https://stackoverflow.com/questions/12330141/dailymotion-api-invalid-authorization-code ), but without success.
Anyone can help me, please?

I suggest you try this way :
include("Dailymotion.php");
$apiKey = "xxxxxxxxxxxxxxxxxxxx";
$apiSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$username = "yourUsername";
$pwd = "yourPassword";
$filepath = "myVideo.avi";
$api = new Dailymotion();
$api->setGrantType(Dailymotion::GRANT_TYPE_PASSWORD, $apiKey, $apiSecret, array('manage_videos', 'write','delete'), array('username' => $user, 'password' => $pwd));
$url = $api->uploadFile($filePath);
$result = $api->call('video.create', array(
'url' => $url,
'title' => $title,
'description' => $description,
'private' => 'false',
'published' => 'true',
'channel' => 'lifestyle'
));
Important: Don't share your API's ID!
That works for me, hope that work for you too !

Related

What is the best php option to connect to outlook imap with oAuth?

What would be the best option to connect to an outlook email account with PHP?
I´m not sure how to declare my credentials with oAuth, should I use my e-mail as username or the client Id key as username? Should I use client secret as password?
I've been trying the following solutions with no success:
https://github.com/javanile/php-imap2
include "inc/php-imap2/vendor/autoload.php";
// Start connection
$mailbox = "{smtp.office365.com:993/imap/ssl/novalidate-cert}";
$token = base64_encode("user=" . $email . "\1auth=Bearer " . $passw . "\1\1");
$imap = #imap2_open($mailbox, $email, $token, OP_XOAUTH2);
// List all mailboxes
if ($imap) {
$mailboxes = imap2_getmailboxes($imap, $mailbox, '*');
var_dump($mailboxes);
} else {
$error = imap2_last_error();
echo $error;
}
Return
Can not authenticate to IMAP server: A0001 NO AUTHENTICATE failed.
https://github.com/Webklex/php-imap
include "inc/php-imap/vendor/autoload.php";
use Webklex\PHPIMAP\ClientManager;
use Webklex\PHPIMAP\Client;
$cm = new ClientManager($options = []);
$client = $cm->make([
'host' => "smtp.office365.com",
'port' => 993,
'encryption' => 'ssl',
'validate_cert' => true,
'username' => $email,
'password' => $passw,
'protocol' => 'imap',
'authentication' => 'oauth',
]);
//Connect to the IMAP Server
$client->connect();
Return
got failure response: NO AUTHENTICATE failed.
PHP Fatal error: Uncaught Webklex\PHPIMAP\Exceptions\AuthFailedException in C:\inetpub\wwwroot\inc\php-imap\src\Client.php:385
Stack trace:
#0 C:\inetpub\wwwroot\inc\php-imap\src\Client.php(371): Webklex\PHPIMAP\Client->authenticate()
#1 C:\inetpub\wwwroot\test.php(57): Webklex\PHPIMAP\Client->connect()
#2 {main}
Next Webklex\PHPIMAP\Exceptions\ConnectionFailedException: connection setup failed in C:\inetpub\wwwroot\inc\php-imap\src\Client.php:391
Stack trace:
#0 C:\inetpub\wwwroot\inc\php-imap\src\Client.php(371): Webklex\PHPIMAP\Client->authenticate()
#1 C:\inetpub\wwwroot\test.php(57): Webklex\PHPIMAP\Client->connect()
#2 {main}
thrown in C:\inetpub\wwwroot\inc\php-imap\src\Client.php on line 391
Any help is appreciated

how to convert destinationAddresses/phone number into hash codes in PHP sms API

I want to create SMS sending application using PHP with SMS API. In my response message I can see success code and success message but my Problem is in my log file says as
Passed Exception exception 'SMSServiceException' with message 'Format
of the address is invalid'
I think problem is, starts when I hash coding phone number. And I don't know how to do that, Please help me.
I have tried to convert phone number using md5() but result is same.
my index.php
$jsonData = array( 'requestId'=> '','message' => 'thismsg hello',
'password' => '25c8db49905003e3347ad861546fce1a',
'sourceAddress' => '77000',
'deliveryStatusRequest' => '1',
'chargingAmount' => '2.00',
'destinationAddresses' => ['88b7a1e8dbf419a2c0835b4f33d06c1a'],//this convert with md5
'applicationId' => 'APP_051000',
'encoding' => '0',
'version' => '1.0',
'binaryHeader' => ''
);
my .log file result:
[01-Feb-2019 08:57:34 Asia/Colombo] Message received msg_header hello
[01-Feb-2019 08:57:35 Asia/Colombo] Passed Exception exception 'SMSServiceException' with message 'Format of the address is invalid.' in /ophielapp/lib/SMSSender.php:58
Stack trace:
#0 /ophielapp/lib/SMSSender.php(46): SMSSender->handleResponse(Object(stdClass))
#1 /ophielapp/lib/SMSSender.php(34): SMSSender->sendRequest('{"applicationId...')
#2 /ophielapp/sms.php(66): SMSSender->sendMessage('hello', '77000')
#3 {main}
I want to correctly send phone number into smsSender.php with hash code and If want to more details of other php file I can provide it.
result in my browser:this is the image of response
this is my smsSender.php
<?php
require_once 'SMSServiceException.php';
class SMSSender{
private $applicationId,
$password,
$serverURL;
public function __construct($serverURL, $applicationId, $password)
{
$this->applicationId = $applicationId;
$this->password = $password;
$this->serverURL = $serverURL;
}
public function broadcastMessage($message){
return $this->sendMessage($message, array('tel:all'));
}
public function sendMessage($message, $addresses){
if(empty($addresses))
throw new SMSServiceException('Format of the address is invalid.', 'E1325');
else {
$jsonStream = (is_string($addresses))?$this->resolveJsonStream($message, array($addresses)):(is_array($addresses)?$this->resolveJsonStream($message, $addresses):null);
return ($jsonStream!=null)?$this->sendRequest($jsonStream):false;
}
}
private function sendRequest($jsonStream){
$opts = array('http'=>array('method'=>'POST',
'header'=>'Content-type: application/json',
'content'=>$jsonStream));
$context = stream_context_create($opts);
$response = file_get_contents($this->serverURL, 0, $context);
return $this->handleResponse(json_decode($response));
}
private function handleResponse($jsonResponse){
$statusCode = $jsonResponse->statusCode;
$statusDetail = $jsonResponse->statusDetail;
if(empty($jsonResponse))
throw new SMSServiceException('Invalid server URL', '500');
else if(strcmp($statusCode, 'S1000')==0)
return true;
else
throw new SMSServiceException($statusDetail, $statusCode);
}
private function resolveJsonStream($message, $addresses){
// $addresses is a array
$messageDetails = array('message'=>$message,
'destinationAddresses'=>$addresses);
$applicationDetails = array('applicationId'=>$this->applicationId,
'password'=>$this->password);
$jsonStream = json_encode($applicationDetails+$messageDetails);
return $jsonStream;
}
public function get_location_stream( $addresse){
$reqDetails = array(
'applicationId'=>$this->applicationId,
'password'=>$this->password,
'serviceType'=>'IMMEDIATE',
'subscriberId'=>$addresse
);
return json_encode($reqDetails);
}
public function getlocation( $addresse){
//$jsonStream = get_location_stream($addresse);
$jsonStream= array(
'applicationId'=>$this->applicationId,
'password'=>$this->password,
'serviceType'=>'IMMEDIATE',
'subscriberId'=>$addresse
);
print_r($jsonStream);
json_encode($jsonStream);
$opts = array('http'=>array('method'=>'POST',
'header'=>'Content-Type: application/json',
'content'=>$jsonStream));
$context = stream_context_create($opts);
$response = file_get_contents('http://localhost:7000/lbs/locate', 0, $context);
echo $response;
//return $this->location_response(json_decode($response));
return json_decode($response);
}
public function location_response($jsonResponse){
$statusCode = $jsonResponse->statusCode;
if(empty($jsonResponse)){
throw new SMSServiceException('Invalid server URL', '500');
}else if(strcmp($statusCode, 'S1000')==0){
return array(
$jsonResponse->longitude,
$jsonResponse->latitude,
$jsonResponse->horizontalAccuracy,
$jsonResponse->freshness,
$jsonResponse->messageId
);
}else{
throw new SMSServiceException($statusDetail, $statusCode);
}
}
public function getResponse($addresse){
$jsonStream= array(
'applicationId'=>$this->applicationId,
'password'=>$this->password,
'serviceType'=>'IMMEDIATE',
'subscriberId'=>$addresse
);
$opts = array('http'=>array('method'=>'POST',
'header'=>'Content-Type: application/json',
'content'=>json_encode($jsonStream)));
$context = stream_context_create($opts);
$response = file_get_contents('http://localhost:7000/lbs/locate', 0, $context);
return json_decode($response);
}
}
?>
destinationAddresses pass as string
'destinationAddresses' =>'88b7a1e8dbf419a2c0835b4f33d06c1a',

How to use Instagram API to var_dump user data?

I found this great resource here: https://github.com/galen/PHP-Instagram-API
Trying to use it to pull some data from Instagram and dump out the data, but I keep running into a problem:
Fatal error:
Uncaught exception 'Instagram\Core\ApiException' with message 'Missing client_id or access_token URL parameter.' in /home/user/Instagram/Core/Proxy.php:553
Stack trace:
#0 /home/user/Instagram/Core/Proxy.php(257): Instagram\Core\Proxy->apiCall('get', 'https://api.ins...')
#1 /home/user/Instagram/Instagram.php(176): Instagram\Core\Proxy->getCurrentUser()
#2 /home/user/public_html/igAnalytics.php(6): Instagram\Instagram->getCurrentUser()
#3 {main} thrown in /home/user/Instagram/Core/Proxy.php on line 553
I guess the client secret isn't being mentioned or the access token isn't being read when I get to my final page.
Here's my layout, my igTest.php file:
<?php
require_once( '_autoloader.php' );
$auth_config = array(
'client_id' => 'myid',
'client_secret' => 'mysecret',
'redirect_uri' => 'http://example.com/igAnalytics.php',
'scope' => array( 'likes', 'comments', 'relationships' )
);
$auth = new Instagram\Auth( $auth_config );
$auth->authorize();
$_SESSION['instagram_access_token'] = $auth->getAccessToken( $_GET['code'] );
$instagram = new Instagram\Instagram;
$instagram->setAccessToken( $_SESSION['instagram_access_token'] );
$current_user = $instagram->getCurrentUser();
?>
Which then redirects to my igAnalytics.php file
<?php
require_once( '_autoloader.php' );
$instagram = new Instagram\Instagram( $_SESSION['instagram_access_token'] );
$current_user = $instagram->getCurrentUser();
var_dump($current_user);
?>
My _autoloader.php:
<?php
require( '_SplClassLoader.php' );
$loader = new SplClassLoader( 'Instagram', '../' );
$loader->register();
?>
Just to clarify what's going on, when I go to igTest.php, it redirects me to login to Instagram. When I login, it takes a second and gets me to that error page/message from above ^.
I believe that my igAnalytics.php file is wrong, but I don't understand how/what I'm missing there to make it work properly.
Check this out-
$instagram = new Instagram([
'apiKey' => 'xxxxxxxxxxxxxxxxx',
'apiSecret' => 'xxxxxxxxxxxxx',
'apiCallback' => 'CALLBACK URL'
]);
if (isset($_GET ['code']) && $_GET ['code'] != "") {
$code = $_GET ['code'];
$data = $instagram->getOAuthToken($code);
$user = $data->user;
var_dump($user);
} else {
$loginUrl = $instagram->getLoginUrl();
header('Location: '.$loginUrl);
}

First time fatal error lost

Hello? Is anybody in there?
I've used this before years ago now I'm back. First time gives me this:
Fatal error: Uncaught Services_Twilio_TinyHttpException in /home/www/skyphilly6.com/twill/twilio-php/Services/Twilio/TinyHttp.php:119 Stack trace: #0 /home/www/skyphilly6.com/twill/twilio-php/Services/Twilio.php(178): Services_Twilio_TinyHttp->__call('post', Array) #1 /home/www/skyphilly6.com/twill/twilio-php/Services/Twilio/ListResource.php(92): Base_Services_Twilio->createData('/2010-04-01/Acc...', Array) #2 /home/www/skyphilly6.com/twill/twilio-php/Services/Twilio/Rest/Calls.php(32): Services_Twilio_ListResource->_create(Array) #3 /home/www/skyphilly6.com/twill/index.php(9): Services_Twilio_Rest_Calls->create('8052629166', '8058130331', 'htttttp://demo.twi...') #4 {main} thrown in /home/www/skyphilly6.com/twill/twilio-php/Services/Twilio/TinyHttp.php on line 119
Here's my short code tried many additional lines same result:
<?php
require('./twilio-php/Services/Twilio.php');
$version = "2010-04-01";
$account_sid = 'ACcfc1ba0d12c58180319486144bef540e'; $auth_token = 'washere';
$client = new Services_Twilio($account_sid, $auth_token, $version);
$client->account->calls- >create('8052629166','8058133333','htttttp://demo.twilio.com/welcome/voice/');
?>
Also tried uncommenting this same result:
<?php
require('./twilio-php/Services/Twilio.php');
$version = "2010-04-01";
//$account_sid = 'SK5b9d2d022b971335e17ee50c813ae231'; $auth_token = 'was';
$account_sid = 'ACcfc1ba0d12c58180319486144bef540e'; $auth_token = 'was';
$client = new Services_Twilio($account_sid, $auth_token, $version);
//try {
//$call=
$client->account->calls->create('8052629166','8058133333','htttttp://demo.twilio.com/welcome/voice/');
//,array(
//'Method' => 'GET',
//'FallbackMethod' => 'GET',
//'StatusCallbackMethod' => 'GET',
//'Record' => 'false', ));
//echo 'Started call: ' . $call->sid;
//} catch (Exception $e) { echo 'Error: ' . $e->getMessage(); }
?>
Please point me in the right direction.
Added:
$http = new Services_Twilio_TinyHttp('https://api.twilio.com',
array('curlopts' => array(
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
))
);
//$client = new Services_Twilio($sid, $token, "2010-04-01", $http);
$client = new Services_Twilio($account_sid, $auth_token, $version,$http);
Noticed it doesn't matter what I use for my token same error
Can't find the error log:
$client->http->debug = true;
Hello?

Add comment to issue using php and JIRA SOAP API

How do I add a comment to a JIRA Issue using PHP and Jura's SOAP API? I have the connection and tested it retrieving an existing issue, all runs good, but when I try the addComment method it returns this:
Fatal error: Uncaught SoapFault exception: [soapenv:Server.userException] org.xml.sax.SAXException: Bad types (class java.util.HashMap -> class com.atlassian.jira.rpc.soap.beans.RemoteComment) in /home/a7348186/public_html/jira.php:46 Stack trace:
#0 /home/a7348186/public_html/jira.php(46): SoapClient->__call('addComment', Array)
#1 /home/a7348186/public_html/jira.php(46):
SoapClient->addComment('16VGN3ohoo', 'NTP->29', Array)
#2 {main} thrown in /home/a7348186/public_html/jira.php on line 46
This is my code:
<?php
$emailplain = $_REQUEST['plain'];
$emailsubject = $_REQUEST['subject'];
$inputkey = $_REQUEST['key'];
$inputsumm = $_REQUEST['summ'];
$client = new SoapClient(NULL,
array(
"location" => "https://server.com/rpc/soap/jirasoapservice-v2?wsdl",
"uri" => "urn:xmethods-delayed-quotes",
"style" => SOAP_RPC,
"use" => SOAP_ENCODED
));
$token = $client->login("user", "pass");
$issueId = $inputkey;
$issue = $client->getIssue($token, $issueId);
echo("assignee:".$issue->assignee);
echo(" created:".$issue->created);
echo(" summary:".$issue->summary);
echo(" issueid:".$issue->key);
print $inputsumm;
$stringsummary = $issue->summary;
$string = $issue->summary;
$emailsubjectregexp = preg_replace('/[a-zA-Z]+/', '', $inputsumm);
$stringsumm = ('summary ~ "' . $emailsubjectregexp . '"');
$jqlstring = $stringsumm;
$searchjql = $client->getIssuesFromJqlSearch($token, $jqlstring, 100);
function printArray ($array, $devolver = false) {
$stringa = '<pre>' . print_r($array, true) . '</pre>';
if ($devolver) return $stringa;
else echo $stringa;
}
printArray($searchjql);
print_r ($searchjql);
$key = $searchjql[0]->key;
echo $key;
$client->addComment($token, $key, array('body' => 'your comment'));
?>
If you notice, the last line contains the code to execute what I want, but with no luck. Any ideas folks?
Change the way you create the Soap client object, change :
$client = new SoapClient(NULL,
array(
"location" => "https://server.com/rpc/soap/jirasoapservice-v2?wsdl",
"uri" => "urn:xmethods-delayed-quotes",
"style" => SOAP_RPC,
"use" => SOAP_ENCODED
));
to:
$client = new SoapClient("https://jira.watchitoo.com/rpc/soap/jirasoapservice-v2?wsdl");
This should work.
Full add comment code:
$issueKey = "key-123";
$username= "JiraUser";
$password= "JiraPassword";
$jiraAddress = "https://your.jira.com/rpc/soap/jirasoapservice-v2?wsdl";
$myComment = "your comment";
$soapClient = new SoapClient($jiraAddress);
$token = $soapClient->login($username, $password);
$soapClient->addComment($token, $issueKey, array('body' => $myComment));

Categories