I would like to get the mp4 links of my own videos for my own website. So I've created a vimeo app and generated a personal access token with following scopes: private, public.
Now I tried to call the data of a video and this is the response: "invalid siganture". I dont't know what I'm doing wrong.
if ( ! defined( 'OPCT_VIMEO_CLIENT_ID' ) ) {
define( 'OPCT_VIMEO_CLIENT_ID', '1234' );
}
if ( ! defined( 'OPCT_VIMEO_CLIENT_SECRET' ) ) {
define( 'OPCT_VIMEO_CLIENT_SECRET', 'dfgdfgdfgE44rrfd/xsdfsdfsdGDFDFGdfgdfg/dfgdfgdfgdfgdf/' );
}
if ( ! defined( 'OPCT_VIMEO_ACCESS_TOKEN' ) ) {
define( 'OPCT_VIMEO_ACCESS_TOKEN', '1234' );
}
if ( ! class_exists( 'phpVimeo' ) ) {
include_once 'lib/vimeo.php';
}
try {
$vimeo = new phpVimeo( OPCT_VIMEO_CLIENT_ID, OPCT_VIMEO_CLIENT_SECRET );
$response = $vimeo->call( 'videos', array( 'video_id', '1234567890' ) );
$this->log( $response );
} catch ( Exception $e ) {
$this->log( 'Vimeo Error API Call: ' . $e->getMessage() );
}
The code you include is part of the old Vimeo library, which uses the old Vimeo API.
The old Vimeo API does not expose source files, so you will need to use the new library as found here: https://github.com/vimeo/vimeo.php
The code will look similar to the following in the new library (Note I have not tested this)
if ( ! defined( 'OPCT_VIMEO_CLIENT_ID' ) ) {
define( 'OPCT_VIMEO_CLIENT_ID', '1234' );
}
if ( ! defined( 'OPCT_VIMEO_CLIENT_SECRET' ) ) {
define( 'OPCT_VIMEO_CLIENT_SECRET', 'dfgdfgdfgE44rrfd/xsdfsdfsdGDFDFGdfgdfg/dfgdfgdfgdfgdf/' );
}
if ( ! defined( 'OPCT_VIMEO_ACCESS_TOKEN' ) ) {
define( 'OPCT_VIMEO_ACCESS_TOKEN', '1234' );
}
if ( ! class_exists( 'phpVimeo' ) ) {
include_once 'lib/vimeo.php';
}
try {
$vimeo = new Vimeo\Vimeo( OPCT_VIMEO_CLIENT_ID, OPCT_VIMEO_CLIENT_SECRET );
$response = $vimeo->request( '/videos/' . $video_id);
$this->log( $response );
} catch ( Exception $e ) {
$this->log( 'Vimeo Error API Call: ' . $e->getMessage() );
}
You will then find the video files in the $response variable.
Related
I am creating a plugin which makes an API call to a book keeping service and I am integrating it with WooCommerce.
After the order is created I am using woocommerce_email_order_details hook to execute my API call using $response = wp_remote_post( $post_url );, where $post_url is modified so that it all works with the API.
Within this response is also a pdf which I am saving to a folder in the uploads folder using WP_Filesystem() API. This part looks like this:
$response = wp_remote_post( $post_url );
if ( is_wp_error( $response ) ) {
$error_code = wp_remote_retrieve_response_code( $response );
$error_message = wp_remote_retrieve_response_message( $response );
return new WP_Error( $error_code, $error_message );
}
$body = json_decode( $response['body'] );
$pdf_link = esc_url( $body->order->pdf );
$pdf_name = esc_html( $body->order->order_number );
$pdf_get = wp_remote_get( $pdf_link );
if ( is_wp_error( $pdf_get ) ) {
$error_code = wp_remote_retrieve_response_code( $pdf_get );
$error_message = wp_remote_retrieve_response_message( $pdf_get );
return new WP_Error( $error_code, $error_message );
}
$pdf_contents = $pdf_get['body'];
$pdf_name = 'order-' . $pdf_name . '.pdf';
$upload_dir = wp_upload_dir();
$new_dir = $upload_dir['basedir'] . '/orders/' . date( 'Y' ) . '/' . date( 'm' );
if ( ! file_exists( $new_dir ) ) {
wp_mkdir_p( $new_dir );
}
global $wp_filesystem;
if ( empty( $wp_filesystem ) ) {
require_once( ABSPATH . '/wp-admin/includes/file.php' );
WP_Filesystem();
}
$wp_filesystem->put_contents(
$new_dir . '/' . $pdf_name,
$pdf_contents,
FS_CHMOD_FILE // predefined mode settings for WP files.
);
I've tested this with a live link on my local server and it all works.
One thing I don't think I can do is escape the contents of a pdf before saving it because that would break it. Even though this is something that the API of the book keeping service sends me, I don't want to assume anything and take it for granted.
What I am most interested in is: is this safe? Are there any possible vectors of attack here, because I wouldn't want to put my client at a risk.
Hi I am using facebook SDKv4 for facebook login on my website
After authentication of app the user is not login into my site neither the details are saving to the database and after authentication i can see the login button
<?php
session_start();
require_once( 'Facebook/HttpClients/FacebookHttpable.php' );
require_once( 'Facebook/HttpClients/FacebookCurl.php' );
require_once( 'Facebook/HttpClients/FacebookCurlHttpClient.php' );
require_once( 'Facebook/Entities/AccessToken.php' );
require_once( 'Facebook/Entities/SignedRequest.php' );
require_once( 'Facebook/FacebookSession.php' );
require_once( 'Facebook/FacebookRedirectLoginHelper.php' );
require_once( 'Facebook/FacebookRequest.php' );
require_once( 'Facebook/FacebookResponse.php' );
require_once( 'Facebook/FacebookSDKException.php' );
require_once( 'Facebook/FacebookRequestException.php' );
require_once( 'Facebook/FacebookAuthorizationException.php' );
require_once( 'Facebook/GraphObject.php' );
require_once( 'Facebook/GraphSessionInfo.php' );
use Facebook\Entities\AccessToken;
use Facebook\Entities\SignedRequest;
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\GraphSessionInfo;
// init app with app id (APPID) and secret (SECRET)
FacebookSession::setDefaultApplication('APPID','SECRET');
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper( 'example.com' );
/***************************************************session handinling*********************************************/
// see if a existing session exists
if ( isset( $_SESSION ) && isset( $_SESSION['fb_token'] ) ) {
// create new session from saved access_token
//$_SESSION['fb_token'] = $session->getToken();
// create a session using saved token or the new one we generated at login
// $session = new FacebookSession( $session->getToken() );
$session = new FacebookSession( $_SESSION['fb_token'] );
// validate the access_token to make sure it's still valid
try {
if ( !$session->validate() ) {
$session = null;
}
} catch ( Exception $e ) {
// catch any exceptions
$session = null;
}
}
if ( !isset( $session ) || $session === null ) {
// no session exists
try {
$session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
// When Facebook returns an error
// handle this better in production code
print_r( $ex );
} catch( Exception $ex ) {
// When validation fails or other local issues
// handle this better in production code
print_r( $ex );
}
}
/*****************************************************session handling*****************************************/
try {
$session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
// When Facebook returns an error
} catch( Exception $ex ) {
// When validation fails or other local issues
}
// see if we have a session
if ( isset( $session ) ) {
// graph api request for user data
$_SESSION['fb_token'] = $session->getToken();
// create a session using saved token or the new one we generated at login
$session = new FacebookSession( $session->getToken() );
$request = new FacebookRequest( $session, 'GET', '/me' );
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
$fuid= $graphObject->getProperty('id'); // To Get Facebook ID
$fname=$graphObject->getProperty('first_name'); // To Get Facebook full name
$lname=$graphObject->getProperty('last_name'); // To Get Facebook full name
$femail=$graphObject->getProperty('email');
$gender=$graphObject->getProperty('gender');
CODE TO SAVE DETAILS TO DB
/*************************************************************post on users walll******************************************************/
// Publish to User’s Timeline
$request = ( new FacebookRequest( $session, 'POST', '/me/feed', array(
'message' => 'Only TEXT Goes Here'
) ) )->execute();
// Get response as an array, returns ID of post
$response = $request->getGraphObject()->asArray();
print_r( $response );
// Graph API to publish to timeline with additional parameters
$request = ( new FacebookRequest( $session, 'POST', '/me/feed', array(
'name' => 'Name',
'caption' => 'CAtion',
'link' => 'example.com',
'message' => 'msg'
) ) )->execute();
// Get response as an array, returns ID of post
$response = $request->getGraphObject()->asArray();
/****************************************************************post on users wall************************************************/
redirect($site_url);
//echo print_r( $graphObject, 1 );
} else {
// show login url
$permissions = ['email', 'user_likes','publish_actions'];
echo '<img src="'.$img_cdn.'fbcon.png">';
}
?>
Can any one tell where i am doing wrong ?
I hope someone helps me with this puzzle.
I tested facebook login v4 on my localhost where it works just fine,
at first it also worked on my live server, but for a mysterious reason it no longer does.
When on my live server (http://www.zenmony.com/test.php) I click the OAuth link, and for some reason I get a 503 error, and facebook throws no exceptions, so there is no way to debug.
here is my code:
FacebookSession::setDefaultApplication( '738781846169261','*******ac965af67d8979be972655c');
$helper = new FacebookRedirectLoginHelper('http://www.zenmony.com/test.php');
//$helper = new FacebookRedirectLoginHelper('http://localhost/test.php');
if ( isset( $_SESSION ) && isset( $_SESSION['fb_token'] ) ) {
$session = new FacebookSession( $_SESSION['fb_token'] );
try {
if ( !$session->validate() ) {
$session = null;
}
} catch ( Exception $e ) {
$session = null;
print_r($e);
exit;
}
}
if ( !isset( $session ) || $session === null ) {
try {
$session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
print_r($ex);
exit;
} catch( Exception $ex ) {
print_r($ex);
exit;
}
}
// see if we have a session
if (isset($session))
{
// save the session
$_SESSION['fb_token'] = $session->getToken();
$session = new FacebookSession( $session->getToken() );
$request = new FacebookRequest( $session, 'GET', '/me' );
$response = $request->execute();
$graphObject = $response->getGraphObject()->asArray();
echo '<pre>' . print_r( $graphObject, 1 ) . '</pre>';
exit;
}
else
{
// show login url
$link = $helper->getLoginUrl( array( 'email', 'user_friends' ) );//&display=popup
echo "LINK";
}
Apparently the scipt goes as far as $session = $helper->getSessionFromRedirect(); but throws no exceptions and I have the 503 error code.
Just in case, here are my facebook application settings:
Please, need any help!
I have updated my facebook api and i'm trying to initiate a session like this,
FacebookSession::setDefaultApplication( 'foo foo','foo foo' );
I get this error on that line,
Fatal error: Class 'facebook\src\Facebook\FacebookSession'not found in /foo/foo/foo/header.php on line 41
My file path is correct...
Any ideas?
Here is my full code,
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// include required files form Facebook SDK
// added in v4.0.5
require_once( 'facebook/src/Facebook/FacebookHttpable.php' );
require_once( 'facebook/src/Facebook/FacebookCurl.php' );
require_once( 'facebook/src/Facebook/FacebookCurlHttpClient.php' );
require_once( 'facebook/src/Facebook/FacebookSession.php' );
require_once( 'facebook/src/Facebook/FacebookRedirectLoginHelper.php' );
require_once( 'facebook/src/Facebook/FacebookRequest.php' );
require_once( 'facebook/src/Facebook/FacebookResponse.php' );
require_once( 'facebook/src/Facebook/FacebookSDKException.php' );
require_once( 'facebook/src/Facebook/FacebookRequestException.php' );
require_once( 'facebook/src/Facebook/FacebookOtherException.php' );
require_once( 'facebook/src/Facebook/FacebookAuthorizationException.php' );
require_once( 'facebook/src/Facebook/GraphObject.php' );
require_once( 'facebook/src/Facebook/GraphSessionInfo.php' );
use facebook\src\Facebook\FacebookHttpable;
use facebook\src\Facebook\FacebookCurl;
use facebook\src\Facebook\FacebookCurlHttpClient;
use facebook\src\Facebook\FacebookSession;
use facebook\src\Facebook\FacebookRedirectLoginHelper;
use facebook\src\Facebook\FacebookRequest;
use facebook\src\Facebook\FacebookResponse;
use facebook\src\Facebook\FacebookSDKException;
use facebook\src\Facebook\FacebookRequestException;
use facebook\src\Facebook\FacebookOtherException;
use facebook\src\Facebook\FacebookAuthorizationException;
use facebook\src\Facebook\GraphObject;
use facebook\src\Facebook\GraphSessionInfo;
// start session
session_start();
// init app with app id and secret
FacebookSession::setDefaultApplication( 'foo foo','foo foo' );
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper( 'http://www.wuno.com/sandbox/' );
// see if a existing session exists
if ( isset( $_SESSION ) && isset( $_SESSION['fb_token'] ) ) {
// create new session from saved access_token
$session = new FacebookSession( $_SESSION['fb_token'] );
// validate the access_token to make sure it's still valid
try {
if ( !$session->validate() ) {
$session = null;
}
} catch ( Exception $e ) {
// catch any exceptions
$session = null;
}
} else {
// no session exists
try {
$session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
// When Facebook returns an error
// handle this better in production code
print_r( $ex );
} catch( Exception $ex ) {
// When validation fails or other local issues
// handle this better in production code
print_r( $ex );
}
}
// see if we have a session
if ( isset( $session ) ) {
// save the session
$_SESSION['fb_token'] = $session->getToken();
// create a session using saved token or the new one we generated at login
$session = new FacebookSession( $session->getToken() );
// graph api request for user data
$request = new FacebookRequest( $session, 'GET', '/me' );
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject()->asArray();
// print profile data
echo '<pre>' . print_r( $graphObject, 1 ) . '</pre>';
// print logout url using session and redirect_uri (logout.php page should destroy the session)
echo 'Logout';
} else {
// show login url
echo 'Login';
}
echo 'sup dude';
?>
Clicking an icon on a webpage triggers a jQuery AJAX call to a PHP script that synchs a local database to a SugarCRM database using SOAP.
By sending myself emails before and after the problematic statements, I can see that the SOAP connection succeeds, but the ensuing login() fails without throwing a SoapFault or a normal Exception.
From the command line, it works.
Thanks in advance for any suggestions
UPDATE: some code...
//Javascript from the webpage
url = 'http://apps.net/synch_with_CRM.php?clientGuid=141516'
// Submit via Ajax if there aren't any errors
jQuery.ajax({
url: url,
success: function(){
jQuery("#dialog-message").dialog({
buttons: {
Ok: function() {
jQuery(this).dialog('close'); /* Closes popup */
}
}
})
jQuery( "#loading_" + crm ).hide();
jQuery( "#icon_sync_" + crm ).show();
}
});
// PHP code from .../apps.net/synch_with_CRM.php
<?php
if ( $_REQUEST['clientGuid'] ) { # get the URL parameter
$client_guid = $_REQUEST['clientGuid'];
}
else if ( $argv ) { # get the command-line parameter
$client_guid = $argv[$argc - 1]; # clientGuid must be last
}
$client = new Client( $client_guid );
$client_id = $client->GetId( );
# connection information is the same for AJAX or command-line
$connection_info = getConnectionInfo( $client_id, 'SugarCRM' );
$API_soap_client = get_connection( $connection_info );
if ( !$API_soap_client ) {
exit( "SOAP client connection failed\n" );
}
# do other stuff here...
# SNIP!
function get_connection( $connection_info ) {
global $soap_session_id;
try {
$options = array( 'location' => $connection_info['url'],
'uri' => $connection_info['uri'],
'trace' => 1 );
$auth_array = array( 'user_name' => $connection_info['username'],
'password' => md5( $connection_info['password'] ) );
$API_soap_client = new soapclient( NULL, $options );
# I get the following email whether by AJAX or command-line
mail( 'programmer#apps.net', 'soapclient', print_r( $API_soap_client, true ) );
$soap_session = $API_soap_client->login( $auth_array );
# I only get this email if the script is run from the command-line
mail( 'programmer#apps.net', 'soap id', print_r( $soap_session, true ) );
$soap_session_id = $soap_session->id;
if ( $soap_session_id != -1 ) return $API_soap_client;
else return false;
}
catch( SoapFault $fault ) { # there is no SoapFault thrown
mail( 'programmer#apps.net', 'soap fault', print_r( $fault, true ) );
}
catch( Exception $e ) { # there is no Exception thrown
mail( 'programmer#apps.net', 'exception', print_r( $e, true ) );
}
} # end get_connection
?>
Anyway you could post some code to highlight the issue? Also, you may want to try doing it over REST versus SOAP since REST will be much faster.