public function request_dropbox()
{
$params['key'] = 'gr3kempuvsiqsli';
$params['secret'] = 'qtdl8lmm9r0rlk1';
$this->load->library('dropbox', $params);
$data = $this->dropbox->get_request_token(base_url());
$this->session->set_userdata('token_secret', $data['token_secret']);
redirect($data['redirect']);
}
//This method should not be called directly, it will be called after
//the user approves your application and dropbox redirects to it
public function access_dropbox()
{
$params['key'] = 'gr3kempuvsiqsli';
$params['secret'] = 'qtdl8lmm9r0rlk1';
$this->load->library('dropbox', $params);
$oauth = $this->dropbox->get_access_token($this->session->userdata('token_secret'));
$this->session->set_userdata('oauth_token', $oauth['oauth_token']);
$this->session->set_userdata('oauth_token_secret', $oauth['oauth_token_secret']);
redirect('welcome/test_dropbox');
}
//Once your application is approved you can proceed to load the library
//with the access token data stored in the session. If you see your account
//information printed out then you have successfully authenticated with
//dropbox and can use the library to interact with your account.
public function test_dropbox()
{
$params['key'] = 'gr3kempuvsiqsli';
$params['secret'] = 'qtdl8lmm9r0rlk1';
$params['access'] = array('oauth_token'=>urlencode($this->session->userdata('oauth_token')),
'oauth_token_secret'=>urlencode($this->session->userdata('oauth_token_secret')));
$this->load->library('dropbox', $params);
$dbobj = $this->dropbox->account();
print_r($dbobj);
}
Blockquote
i have used Dropbox library https://github.com/jimdoescode/CodeIgniter-Dropbox-API-Library
When i call to function request_dropbox() it gives me error in api "Fatal error: Call to undefined function curl_init() in C:\xampp\htdocs\reports\application\libraries\Dropbox.php on line 478"
please help me how to access dropbox files.
Please look at your errors more carefully, it turns out that curl is not enabled on your Xampp environment.
This should help you out to enable CURL and get you going again.
How to enable curl in xampp?
Related
I am trying to use the Sinch Rest API with PHP to mute and unmute specific participants from Conference calls but have not been able to find an example of how to send an application signed request with PHP. I have been trying to work off of this documentation from Sinch here https://www.sinch.com/docs/voice/rest/index.html#muteunmuteconfparticipant
My initial guesses are that this would require the use of CURL and that I would also need to use similar pieces of this example to sign my application but I"m not sure how to combine the two. https://github.com/sinch/php-auth-ticket
Any help appreciated. Thanks!
edit: #cjensen I added this code snippet I've been working on to try and use as the signed request maker. It's very similar to that github link above
<?php
class SinchTicketGenerator
{
private $applicationKey;
private $applicationSecret;
public function __construct($applicationKey, $applicationSecret)
{
$this->applicationKey = $applicationKey;
$this->applicationSecret = $applicationSecret;
}
public function generateTicket()
{
$request = [
'command' => 'mute',
];
$requestJson = preg_replace('/\s+/', '', json_encode($request));
$requestBase64 = $this->base64Encode($requestJson);
$digest = $this->createDigest($requestJson);
$signature = $this->base64Encode($digest);
$requestSigned = $requestBase64.':'.$signature;
return $requestSigned;
}
private function base64Encode($data)
{
return trim(base64_encode($data));
}
private function createDigest($data)
{
return trim(hash_hmac('sha256', $data, base64_decode($this->applicationSecret), true));
}
}
$generator = new SinchTicketGenerator('app-key', 'app-secret');
$signedrequest = $generator->generateTicket();
echo $signedrequest;
?>
I have this method below to download a file from an API server. But its not working properly, when the user clicks in the button that calls the getFile() method it appears at first in the page the error
Trying to get property of non-object
But if the user click in the browser refresh button the file is downloaded.
So it seems that for the file be generated is necessary send two requests and in the first appears
Trying to get property of non-object
In the second the file is transfered, in the third it appears again
Trying to get property of non-object
In the API says that to download the file is an asynchronous operation, which means that the file may not be ready immediately. I dont know if the issue can be because of that.
Code:
public function getFile($regId){
$client = new \GuzzleHttp\Client();
$user = Auth::user();
$registration = $user->registrations()->with(["proforma"])->where("id", $regId)->first();
$proforma = $registration->proforma->proforma_number;
$getProforma = $client->request('GET', 'https://...'.$proforma.'.json', [
'query' => ['api_key' => '...'],
]);
$response = $getProforma->getBody()->getContents();
$url = null;
if(!empty($response)) {
$response = json_decode($response);
$url = !empty($response->output->pdfUrl) ? $response->output->pdfUrl : '';
}
header("Location: $url");
}
public function getFile($regId)
{
$registration = auth()->user()->registrations()->with(["proforma"])->where("id", $regId)->first();
$proforma = $registration->proforma->proforma_number;
$getProforma = json_decode(file_get_contents('https://...' . $proforma . '.json?api_key=.....'));
// $getProforma->output here was your problem so I advice you to: dd($getProforma);
$url = ! empty(optional($getProforma->output)->pdfUrl) ? optional($getProforma->output)->pdfUrl : '/'; // it will redict home if it couldn't find the PDF URL
return redirect($url);
}
I want to give a 3rd party PHP application access to Yii2 user data (HumHub) and have tried this:
function getUserId() {
require_once('../protected/vendor/yiisoft/yii2/Yii.php');
$yiiConfig = require('../protected/config/common.php');
(new humhub\components\Application($yiiConfig));
$user = Yii::$app->user->identity;
return $user;
}
This does not work. There are no errors up until new humhub\components\Application($yiiConfig) but then the 3rd party app breaks with no error thrown and the function does not return anything.
I did find this solution which does not work.
Is there are reason this does not work or is there an alternate solution to getting Yii2 user data properly?
This is how to do it in HumHub V1.0
require_once('../protected/vendor/yiisoft/yii2/Yii.php');
$config = yii\helpers\ArrayHelper::merge(
require('../protected/humhub/config/common.php'),
require('../protected/humhub/config/web.php'),
(is_readable('../protected/config/dynamic.php')) ? require('../protected/config/dynamic.php') : [],
require('../protected/config/common.php'),
require('../protected/config/web.php')
);
new yii\web\Application($config); // No 'run()' invocation!
Now I can get $user object:
$user = Yii::$app->user->identity;
Indeed an error should be thrown, but, the error settings of your PHP may be overridden or set to not display errors.
You call undefined object Yii::$app->user->identity. The reason, from documentation because you have not initialized the Yii object. So your code should be as follows:
function getUserId() {
require_once('../protected/vendor/yiisoft/yii2/Yii.php');
$yiiConfig = require('../protected/config/common.php');
(new humhub\components\Application($yiiConfig)); // try to comment this line too if it does not work
// Add The Following Line
new yii\web\Application($yiiConfig); // Do NOT call run() here
$user = Yii::$app->user->identity;
return $user;
}
I am trying to setup an Oauth server using the pecl-php oauth library http://php.net/manual/en/book.oauth.php
This code assumes that the client has already received a user verified access token, for simplicity sake I've not included any database calls and have hardcoded matching values into my client and provider.
Class OauthVerify
{
private static $consumer_secret = 'f63ed7f7a8899e59d3848085c9668a0d';
private static $token_secret = '72814e6059441037152eecef2e8559a748b84259';
private $provider;
public function __construct()
{
$this->provider = new OAuthProvider();
$this->provider->consumerHandler(array($this,'consumerHandler'));
$this->provider->timestampNonceHandler(array($this,'timestampNonceHandler'));
$this->provider->tokenHandler(array($this,'checkAccessToken'));
}
//Check the client request
public function checkRequest()
{
try {
$this->provider->checkOAuthRequest();
} catch (Exception $Exception) {
return OAuthProvider::reportProblem($Exception);
}
return true;
}
public static function timestampNonceHandler($Provider)
{
//I'm leaving out this logic now, to keep it simple and for testing purposes
return OAUTH_OK;
}
public static function consumerHandler($Provider)
{
//I'm leaving out this logic now, to keep it simple and for testing purposes
$Provider->consumer_secret = self::$consumer_secret;
return OAUTH_OK;
}
public static function checkAccessToken($Provider)
{
$Provider->token_secret = self::$token_secret;
return OAUTH_OK;
}
}
The above code should give me the barebones I need to authenticate an Oauth request.
Before any particular route is executed I call the $OauthVerify->checkRequest() method which checks if the client request is valid, however the server keeps throwing a 'signatures do not match' error. I don't think that the problem is with the clients as I've tried both postman (for chrome) and a PHP implementation and they both generate the same signature. I have however for interest sake included my client call.
$consumer_key = '87d6d61e87f0e30d8747810ae40041d1';
$consumer_secret = 'f63ed7f7a8899e59d3848085c9668a0d';
$token= 'b9d55b3ec4b755d3fe25d7a781da1dfd044b5155';
$token_secret = '72814e6059441037152eecef2e8559a748b84259';
$timestamp = '1417515075';
$nonce = '9QV4rn';
$version = '1.0';
$method = 'GET';
$url = 'https://localhost/micro/v1/nappi';
try {
$oauth = new OAuth($consumer_key, $consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
$oauth->disableSSLChecks();
$oauth->setNonce($nonce);
$oauth->setTimestamp($timestamp);
$oauth->setToken($token, $token_secret);
$oauth->setVersion($version);
$oauth->fetch("$url");
$json = json_decode($oauth->getLastResponse());
print_r($json);
}
catch(OAuthException $E) {
print_r($E);
}
I've burned a good couple of hours trying to figure this out, someone please help!
I finally managed to solve it, my .htaccess file had a rewrite rule that was processing a _url parameter for my framework. This parameter was ofcourse being included in the signature that the server generated. I simply instructed OAuth Provider to ignore the the _url parameter in my constructor:
$this->provider->setParam('_url',NULL);,
that was all it took, everything runs perfectly now.
Hi I am using contextIO api for fetch emails.I got a code from GitHub ,but it shows some errors.I am using this code ,
include_once("class.contextio.php");
// see https://console.context.io/#settings to get your consumer key and consumer secret.
$contextIO = new ContextIO('asssasas','sdsd1111sdsdsd');
$accountId = null;
// list your accounts
$r = $contextIO->listAccounts();//print_r($r);
foreach ($r->getData() as $account) {
echo $account['id'] . "\t" . join(", ", $account['email_addresses']) . "\n";
if (is_null($accountId)) {
$accountId = $account['id'];
}
}
But it shows a n error
Fatal error: Call to a member function getData() on a non-object
Is it need a seperate gmail authentication? anyone please help me
All of the functions in the ContextIO library return a ContextIOResponse object, or false if the API returns an http error code. Check for if($r !== false) before you call getData() on $r and you should be good to go!
(Note: I work on the context.io team and am currently the primary developer on the PHP libraries.)