HelloSign PHP SDK - Class "HelloSignSDK\Configuration" not found - php

I tried with the below code to get the Account details, it's working fine.
require_once __DIR__ . "/vendor/autoload.php";
$apikey = "<API KEY FROM HELLOSIGN>";
$client = new HelloSign\Client($apikey);
$account = $client->getAccount();
But when I try with the below code to get an Account using SDK, reference link: https://developers.hellosign.com/api/reference/operation/accountGet/:
require_once __DIR__ . "/vendor/autoload.php";
$config = HelloSignSDK\Configuration::getDefaultConfiguration();
// Configure HTTP basic authorization: api_key
$config->setUsername("YOUR_API_KEY");
// or, configure Bearer (JWT) authorization: oauth2
// $config->setAccessToken("YOUR_ACCESS_TOKEN");
$api = new HelloSignSDK\Api\AccountApi($config);
try {
$result = $api->accountGet(null, 'jack#example.com');
print_r($result);
} catch (HelloSignSDK\ApiException $e) {
$error = $e->getResponseObject();
echo "Exception when calling HelloSign API: "
. print_r($error->getError());
}
It throws an error: Fatal error: Uncaught Error: Class "HelloSignSDK\Configuration" not found
Added autoload, why is this issue if using SDK? Kindly help!

Related

Facebook login with php grapth sdk gives a 404 error

I have a facebook login button on a site, which used to work. I haven't changed anything as far as I know, but now it just gives a Not Found error:
The requested URL /https://www.facebook.com/v3.0/dialog/oauth was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Not sure if it would help, but this is in my fbConfig.php file:
require_once __DIR__ . '/facebook-php-sdk/autoload.php';
// Include required libraries
use Facebook\Facebook;
use Facebook\Exceptions\FacebookResponseException;
use Facebook\Exceptions\FacebookSDKException;
//some code to set the correct $appId and $appSecret that developers.facebook gave me
$redirectURL = $url; //Callback URL
$fbPermissions = array('email'); //Optional permissions
$fb = new Facebook(array(
'app_id' => $appId,
'app_secret' => $appSecret,
'default_graph_version' => 'v3.0',
));
// Get redirect login helper
$helper = $fb->getRedirectLoginHelper();
$_SESSION['FBRLH_state']=$_GET['state'];
// Try to get access token
try {
if(isset($_SESSION['facebook_access_token'])){
$accessToken = $_SESSION['facebook_access_token'];
}else{
$accessToken = $helper->getAccessToken();
}
} catch(FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
A cursory glance at The PHP Docs indicates the current default_graph_version version is v2.2. So that means 1 of 2 things:
You're using a version that doesn't exist
You're using a beta version which is caveat emptor
Try bringing the version back to v2.2 and seeing if it works. Also ensure you're using an up-to-date, unmodified, official version of their SDKs.

Failing to get an Facebook App to post to a Page's Wall, as that Page

I am struggling going round in circles getting an Facebook App to post to a Page's Wall, as that Page.
** Note: I put out a 300 point bounty to update an outdated answer of a related, well-viewed, existing question. Happy to award anyone who also answers there with the updated, working, solution
In brief:
I have the App Secret and ID
I have Page ID
I am relying on an in-code approach to generating the token I need.
It is based on a solution I saw posted on the SDK GitHub page but it does not work
I am using API v 2.9
I am using the latest PHP SDK
It's just been hard.
The solution I used is purely based on the one below:
<?php
define('FACEBOOK_SDK_V4_SRC_DIR', __DIR__ . '/Facebook');
require_once __DIR__ . '/Facebook/autoload.php';
use Facebook\FacebookRequest;
$app_id = {{your app-id}};
$app_secret = {{your app-secret}};
$fb = new Facebook\Facebook([
'app_id' => $app_id,
'app_secret' => $app_secret,
'default_graph_version' => '{{your app-version}}',
]);
$token = $fb->get(
'/oauth/access_token?client_id=' . $app_id . '&'.
'client_secret=' . $app_secret . '&'.
'grant_type=client_credentials');
$get_token = $token -> getdecodedBody();
$access_token = $get_token['access_token'];
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get('/{{your facebook name}}', $access_token);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$body = $response->getBody();
print_r($body);
?>
I am certainly not lazy. I have been stuck on this issue for weeks.
I have tried the following different solutions and have gotten stuck in either a permissions related issue that was also related to depracated functionality and API calls or getting the right token to do it.
Posting to a facebook page from a website using curl (using a pure CURL approach - "The user hasn't authorized the application to perform this action")
Facebook SDK returned an error: You must provide an access token. Php Facebook Api - (suggests that I support login and redirection callback - yet I do not want any user intervention everytime when posting onto the page)
Graph returned an error: Invalid appsecret_proof provided in the API argument - Previous attempt was based on this example but the appsecret-proof issue
Simple example to post to a Facebook fan page via PHP? - Another CURL-based approach that failed me
https://stackoverflow.com/a/14212125/919426 - Best explained step by
step process for permissions and tokens, but still failed
Update:
Tried the following and got the error "Invalid appsecret_proof provided in the API argument"
$fb = new Facebook([
'app_id' => 'APP_ID',
'app_secret' => 'APP_SECRET',
'default_graph_version' => 'v2.9',
]);
$postData = [
'message' => "Test Message",
'picture' => 'https://www.website.com/image.jpg'
];
try
{
// 'LONG_LIVED_PAGE_ACCESS_TOKEN' obtained by going to https://developers.facebook.com/tools/debug/accesstoken and clicking
// "Extend Access Token"
$response = $fb->post('/' . 'PAGE_ID' . '/feed', $postData,"LONG_LIVED_PAGE_ACCESS_TOKEN");
}
catch (FacebookResponseException $e)
{
var_dump("Facebook Response Exception occured: \n" . $e);
exit;
}
catch(FacebookSDKException $e)
{
var_dump("Generic Facebook SDK Exception occured: \n" . $e);
exit;
}
catch(Exception $e)
{
var_dump("Uknown Exception occured while attempting to call the Facebook SDK API: \n" . $e);
exit;
}
There are countless more that I have tried and failed.

Download CSV file using Google Drive V3(V2 works perfect) throws error 403

I m using DRIVE V2 WITH Service Account to download CSV file,This one is working fine. I want to migrate DRIVE V2 to DRIVE V3 .So i changed my script as per below google documents
I. Download a file in drive V3
PHP Library & Drive API V3 used in this sample:
1.Sample script download CSV file using Drive V3
Method used: Using alt=media
Reason: this method only available in DRIVE V3
<?php
set_include_path( get_include_path() . PATH_SEPARATOR . 'Google' );
require_once 'Google/autoload.php';
require_once 'Google/Client.php';
require_once 'Google/Service/Drive.php';
try{
//Get service document
$service = get_service_document();
//Download a csv file
$data = $service->files->get("FILE ID", array( 'alt' => 'media'));
print_r($data);
}
catch(Exception $e){
print_r($e->getMessage());
}
//function to get service
function get_service_document(){
$userstamp='user#example.com';
//Enable below two lines if let know the clientid,tokens,etc.,
$driveService=buildServiceDrive($userstamp,"SERVICE_ACCOUNT","https://www.googleapis.com/auth/drive","KEY.p12");
return $driveService;
}
//building service
function buildServiceDrive($userEmail,$service_id,$scope,$service_filename) {
$key = file_get_contents($service_filename);
$auth = new Google_Auth_AssertionCredentials(
$service_id,
array($scope),
$key);
$auth->sub = $userEmail;
$client = new Google_Client();
$client->setAssertionCredentials($auth);
return new Google_Service_Drive($client);
}
RESULT:
I got the below issue
Error calling GET https://www.googleapis.com/drive/v3/files/0B5pkfK_IBDxjeHlTTDFFY01CXzQ?alt=media: (302)
Moved Temporarily
The document has moved here.
After clicked here. I saw below error.
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
}
II. Download a file in Drive V2
I used alternate method to download CSV file from drive.
PHP Library & Drive API V2 used in this sample:
2.Sample Script download CSV file using Drive V2
Method used : Alternate method: using downloadUrl
<?php
set_include_path( get_include_path() . PATH_SEPARATOR . 'Google' );
require_once 'Google/autoload.php';
require_once 'Google/Client.php';
require_once 'Google/Service/Drive.php';
try{
//Get service document
$service = get_service_document();
$data = $service->files->get("FILE ID");
$url=$data->downloadUrl;
$data=downloadFile($service,$url);
print_r($data);
}
catch(Exception $e){
print_r($e->getMessage());
}
//Alternate method using download URL
function downloadFile($service, $downloadUrl)
{
if ($downloadUrl) {
$request = new Google_Http_Request($downloadUrl, 'GET', null, null);
$httpRequest = $service->getClient()->getAuth()->authenticatedRequest($request);
if ($httpRequest->getResponseHttpCode() == 200) {
return $httpRequest->getResponseBody();
} else {
echo "errr";
return null;
}
} else {
echo "empty";
return null;
}
}
//function to get service
function get_service_document(){
$driveService =buildServiceDrive(user#example.com',"SERVICE-ACCOUNT","https://www.googleapis.com/auth/drive","KEY.p12");
return $driveService;
}
//building service
function buildServiceDrive($userEmail,$service_id,$scope,$service_filename) {
$key = file_get_contents($service_filename);
$auth = new Google_Auth_AssertionCredentials(
$service_id,
array($scope),
$key);
$auth->sub = $userEmail;
$client = new Google_Client();
$client->setAssertionCredentials($auth);
return new Google_Service_Drive($client);
}
Result:
i got CSV file records, working fine
Plz help me resolve to download a CSV file using G DRIVE V3. Is there any regression or functions lagging b/w V2, V3?
Since the Google Drive API for PHP is beta version, realize that some errors can be experienced by developers.
Error calling GET
https://www.googleapis.com/drive/v3/files/0B5pkfK_IBDxjeHlTTDFFY01CXzQ?alt=media:
(302) Moved Temporarily The document has moved here.
In this case, here's link is:
https://www.googleapis.com/download/drive/v3/files/0B5pkfK_IBDxjeHlTTDFFY01CXzQ?alt=media
You can see the API Server suggest the new link "download" before "/drive...".
In Google Drive Client Library V3, here is the solution you can fix manually by adding the following code to src/Google/Http/REST.php after line 147:
if($requestUrl=='drive/v3/files/{fileId}' && $params['alt']['value']=='media')
$requestUrl = "download/".$requestUrl;
Hope this help... :)

fitbit php auth doesn't work

After 10 hours of trying various fitbit php libraries I'm turning to stackoverflow for help.
This doesn't work: https://github.com/heyitspavel/fitbitphp
Using
$profile = $fitbit->getProfile();
with that library returns
Fatal error: Uncaught exception 'FitBitException' with message 'Your Fitbit request failed. Code: 400' in /var/www/api/fitbitphp.php:324 Stack trace: #0 /var/www/api/addFitbit.php(22): FitBitPHP->getProfile() #1 {main} thrown in /var/www/api/fitbitphp.php on line 324
This the library on the fitbit website, seems like a lot of people have a problem with this.
public function getProfile()
{
$headers = $this->getHeaders();
try {
$this->oauth->fetch($this->baseApiUrl . "user/" . $this->userId . "/profile." . $this->responseFormat, null, OAUTH_HTTP_METHOD_GET, $headers);
} catch (Exception $E) {
}
$response = $this->oauth->getLastResponse();
$responseInfo = $this->oauth->getLastResponseInfo();
if (!strcmp($responseInfo['http_code'], '200')) {
$response = $this->parseResponse($response);
if ($response)
return $response;
else
throw new FitBitException($responseInfo['http_code'], 'Fitbit request failed. Code: ' . $responseInfo['http_code']);
} else {
throw new FitBitException($responseInfo['http_code'], 'Your Fitbit request failed. Code: ' . $responseInfo['http_code']);
}
}
I tried this here as well but it doesn't return the user token or session id https://github.com/nostra999/fitbit-api
Perhaps missed out the init step, as described in the lib README file (https://github.com/heyitspavel/fitbitphp/blob/master/README.md)
Simple working usage is:
<?php
define('FITBIT_KEY', '777'); // The application key registered
define('FITBIT_SECRET', '777'); // The application secret registered
$fitbit = new FitBitPHP(FITBIT_KEY, FITBIT_SECRET);
$fitbit->initSession('http://localhost:8080/fibit'); // callback URL
$fitbit->getProfile();
Also from the Fitbit API Documentation:
https://wiki.fitbit.com/display/API/API+Response+Format+And+Errors#APIResponseFormatAndErrors-Response
400 Bad Request Any case where either endpoint doesn't exist, resource
path parameters are invalid, POST request parameters are invalid or no
Authentication header provided. This doesn't include invalid specific
resource ids
If this does not help, please provide the full code that you run, not just
$profile = $fitbit->getProfile();

Uncaught PPConnectionException Http response code 400

Basically what I can see is that I am failing to create the apiContext object. Can anyone see where the error is? Please tell me how I can improve the question.
Here is the error:
Fatal error: Uncaught exception 'PayPal\Exception\PPConnectionException'
with message 'Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment.' in /vendor/paypal
/sdk-core-php/lib/PayPal/Core/PPHttpConnection.php:104 Stack trace: #0
/vendor/paypal/sdk-core-php/lib/PayPal/Transport/PPRestCall.php(44):
PayPal\Core\PPHttpConnection->execute('{"intent":"sale...') #1 /vendor/paypal
/rest-api-sdk-php/lib/PayPal/Api/Payment.php(246): PayPal\Transport
\PPRestCall->execute(Array, '/v1/payments/pa...', 'POST',
'{"intent":"sale...') #2 /pymt.php(38): PayPal\Api
\Payment->create(Object(PayPal\Rest\ApiContext)) #3 {main} thrown in /vendor
/paypal/sdk-core-php/lib/PayPal/Core/PPHttpConnection.php on line 104
This is the PHP sample I'm using. I am trying to run it off my server. If a customer clicks the pay with paypal button, it runs the following sample script:
<?php
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Address;
use PayPal\Api\Amount;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\FundingInstrument;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;
session_start();
$payer = new Payer();
$payer->setPayment_method('paypal');
$amount = new Amount();
$amount->setCurrency('USD');
$amount->setTotal('1.00');
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription('This is the payment description.');
$baseUrl = getBaseUrl();
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturn_url('baseUrl/sale.php');
$redirectUrls->setCancel_url('baseUrl/saleFail.php');
$payment = new Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setRedirect_urls($redirectUrls);
$payment->setTransactions(array($transaction));
try {
$payment->create($apiContext);
} catch (\PPConnectionException $ex) {
echo 'Exception: ' . $ex->getMessage() . PHP_EOL;
var_dump($ex->getData());
exit(1);
}
foreach ($payment->getLinks() as $link) {
if ($link->getRel() == 'approval_url') {
$redirectUrl = $link->getHref();
}
}
$_SESSION['paymentId'] = $payment->getId();
if(isset($redirectUrl)) {
header('Location: $redirectUrl');
exit;
}
Here's the redacted bootstrap.php:
<?php
/*
* Sample bootstrap file.
*/
// Include the composer autoloader
if(!file_exists(__DIR__ .'/vendor/autoload.php')) {
echo "The 'vendor' folder is missing. You must run 'composer update --no-dev' to resolve application dependencies.\nPlease see the README for more information.\n";
exit(1);
}
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/common.php';
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
$apiContext = getApiContext();
/**
Helper method for getting an APIContext for all calls
*
* #return PayPal\Rest\ApiContext
*/
function getApiContext() {
// ### Api context
// Use an ApiContext object to authenticate
// API calls. The clientId and clientSecret for the
// OAuthTokenCredential class can be retrieved from
// developer.paypal.com
$apiContext = new ApiContext(
new OAuthTokenCredential(
'MY CLIENT ID',
'MY SECRET'
)
);
// Register the sdk_config.ini file in current directory
// as the configuration source.
if(!defined("PP_CONFIG_PATH")) {
define("PP_CONFIG_PATH", __DIR__);
}
return $apiContext;
}
Can anyone help? Let me know if you need more info. Thanks up front.
I got the same problem too, I found that if any param was wrong (for example: an invalid card number or a invalid currency format), php SDK throw Connection Exception, Instead of returning certain Json Message(when I organize POST data myself and send with curl , It's OK)! I wander if it is reasonable to design like this, Or we just missed something!...

Categories