Get link after upload file on mediafire api - php

Hi, I am trying to get file link after upload afile using mediafire api
$appId = "";
$apiKey = "";
$email = "";
$password = "";
include("../mflib.php");
$mflib = new mflib($appId, $apiKey);
$mflib->email = $email;
$mflib->password = $password;
$sessionToken = $mflib->userGetSessionToken();
$uploadKey = $mflib->fileUpload($sessionToken, "500px-PHP.png");
$mp3=$mflib->fileGetLinks($quickkey,'direct_download',$sessionToken);
But it gives me the following error:
Error - Get file links : "Invalid parameter 'quickkey' specified" (0)
The file is already uploaded but I can't get the link
I trying to get the $quickkey.
What is the right way to get it?

Once you completed the upload, use the key from the response (response.doupload.key) to poll the upload. it is known as the upload_key.
The whole idea is to see if the upload has truly been completed (which should produce a quickkey).
When you poll the upload (intermittently , say a couple of secs) using the upload_key,
check that the status(response.doupload.status==99) then get the quickkey (response.doupload.quickkey)
This is the quickkey you use in your getting the link
pls see links:
https://www.mediafire.com/developers/upload.php#poll_upload
https://www.mediafire.com/developers/download.php#direct_download_link

$data=$mflib->filePollUpload($sessionToken, $uploadKey);
$quickkey=$data['quickkey'];
$mp3=$mflib->fileGetLinks($quickkey,'direct_download',$sessionToken);
**You need to provide $quickkey but you didn't declare this veriable.**

Related

Sending a message to an user in moodle

I am currently trying to implement what should be a simple task and send a message to one and / or more users via Moodle.
In the process I found 2 guides, which confused me at first.
Messaging 2.0 and Message API. Both have some differences and I didn't understand if my plugin needs to register as a Message Producer or not.
Unfortunately, I just can't get my message to be sent. I logged in with the user and checked the mailbox, no message there. Any help is appreciated.
What I did:
Created message.php within my db - folder and inserted the following code:
<?php
defined('MOODLE_INTERNAL') || die();
$messageproviders = array (
'datenotification' => array (
)
);
After that I expanded my language file with this:
$string['messageprovider:datenotification'] = 'Reminder for a presentation';
Like the guide advised, I updated my plugin to insert my messageprovider in the table mdl_message_providers. Finally, I implemented the actual sending of the message.
$eventdata = new \core\message\message();
$eventdata->component = 'local_reminder'; // the component sending the message. Along with name this must exist in the table message_providers
$eventdata->name = 'datenotification'; // type of message from that module (as module defines it). Along with component this must exist in the table message_providers
$eventdata->userfrom = core_user::get_noreply_user(); // user object , no-reply
$eventdata->userto = $user; // user object from database
$eventdata->subject = 'Test message';
$eventdata->fullmessage = 'This is my test message';
$eventdata->fullmessageformat = FORMAT_PLAIN; // text format
$eventdata->fullmessagehtml = '<p>This is my test message</p>';
$eventdata->smallmessage = '';
$eventdata->courseid = $course_id; // This is required in recent versions, use it from 3.2 on https://tracker.moodle.org/browse/MDL-47162
$result = message_send($eventdata);
Debugging:
var_dump($eventdata); //-> All data is included
var_dump($result); // returns int(5), id of message, no error
Adding the comment as an answer for future reference
Check if the message is installed and enabled via site admin > messaging > notification settings or direct to yoursite/admin/message.php

Trying to add an attachment to an Estimate via PHP (works but, doesn't.)

This is my second day messing with the PHP SDK, I've encountered a road block with uploading an attachment to an Estimate with my code. I wanted a PHP form where one can upload a file and shoot it into the QBO company; my first step was to first try and set a static variable to see if it works, my code look slike this:
$Estimate = $dataService->query("SELECT * FROM Estimate WHERE DocNumber in ('{$ID}')");
// Create a new IPPAttachable
$up = "http://www.somedomain.com/test.pdf";
$sendMimeType = "application/pdf";
$randId = rand();
$entityRef = new IPPReferenceType($Estimate->Id);
$attachableRef = new IPPAttachableRef($entityRef);
$objAttachable = new IPPAttachable();
$objAttachable->FileName = $randId."TEST02.pdf";
//$objAttachable->AttachableRef = $Estimate->DocNumber;
$objAttachable->AttachableRef = $attachableRef;
$objAttachable->Note = "Test";
$objAttachable->ContentType = $sendMimeType;
$resultObj = $dataService->Upload($up,
$objAttachable->FileName,
$sendMimeType,
$objAttachable);
This code fires, adds an attachment to the proper estimate but the attachment is less than 1k and is unreadable. Almost as if it never fetched the document to attach, it simply made some kind of a "generic" success.
Can anyone assist with updating the above code? I'm sure its right in front of me, but I keep missing.
Thank you!

How to invoke the demo url using VinceG php-first-data-api

I am trying to integrate First Data e4 Gateway using PHP. I downloaded the VinceG/php-first-data-api PHP First Data Service API class. The code comes with some examples.
I have my Terminal ID (API_LOGIN) and Password (32 character string).
What confuses me is that when I use one of the examples, I don't know how to tell the class that I want to use the demo url, not the production url.
The class comes with two constants:
const LIVE_API_URL = 'https://api.globalgatewaye4.firstdata.com/transaction/';
const TEST_API_URL = 'https://api.demo.globalgatewaye4.firstdata.com/transaction/';
In the First Data console, when I generated my password, it said to use the v12 api, /transaction/v12, so I changed the protected $apiVersion = 'v12';
All I want to do is write my first development transaction using First Data e4. I have yet to get any kind of response. Obviously I need a lot of hand holding to get started.
When I set up a website to use BalancedPayments, they have a support forum that's pretty good, and I was able to get that running fairly quickly. First Data has a lot of documentation, but for some reason not much of it has good PHP examples.
My hope is that some expert has already mastered the VinceG/php-first-data-api, and can help me write one script that works.
Here's the pre-auth code I'm using, that invokes the FirstData class:
// Pre Auth Transaction Type
define("API_LOGIN", "B123456-01");
define("API_KEY", "xxxxxxxxxxyyyyyyyyyyyyzzzzzzzzzz");
$data = array();
$data['type'] = "00";
$data['number'] = "4111111111111111";
$data['name'] = "Cyrus Vance";
$data['exp'] = "0618";
$data['amount'] = "100.00";
$data['zip'] = "33333";
$data['cvv'] = "123";
$data['address'] = "1111 OCEAN BLVD MIAMI FL";
$orderId = "0001";
require_once("FirstData.php");
$firstData = new FirstData(API_LOGIN, API_KEY, true);
// Charge
$firstData->setTransactionType(FirstData::TRAN_PREAUTH);
$firstData->setCreditCardType($data['type'])
->setCreditCardNumber($data['number'])
->setCreditCardName($data['name'])
->setCreditCardExpiration($data['exp'])
->setAmount($data['amount'])
->setReferenceNumber($orderId);
if($data['zip']) {
$firstData->setCreditCardZipCode($data['zip']);
}
if($data['cvv']) {
$firstData->setCreditCardVerification($data['cvv']);
}
if($data['address']) {
$firstData->setCreditCardAddress($data['address']);
}
$firstData->process();
// Check
if($firstData->isError()) {
echo "!!!";
// there was an error
} else {
echo "###";
// transaction passed
}
My number one problem was that I had not created (applied for, with instant approval) a
demo account on First Data. I didn't realize this was a separate thing on First Data. On Balanced Payments, for instance, you have one account, and you can run your script on a test url with test values.
From the Administration panel, click "Terminals", then your Gateway number on the ECOMM row (will look something like AH1234-03), then you have to click "Generate" on password save it to your personal notes), then click UPDATE.
Now replace your parameter values in your test scripts. I use a variable assignment block that looks something like this:
define("API_LOGIN", "AH1234-05"); //fake
define("API_KEY", "44p7797xxx790098z1z2n6f270ys1z0x"); //fake
$data = array();
$data['type'] = "03";
$data['number'] = "4111111111111111";
$data['name'] = "Cyrus Vancce";
$data['exp'] = "0618";
$data['amount'] = "100.00";
$data['zip'] = "33320";
$data['cvv'] = "123";
$data['address'] = "1234 N OCEAN BLVD MIAMI BEACH FL";
$orderId = "0001";
require_once("FirstData.php");
$firstData = new FirstData(API_LOGIN, API_KEY, true);
at the end of the VinceG test scripts, I output my gateway response with a print_r, like this:
$firstData->process();
// Check
if($firstData->isError()) {
echo "!!!";
// there was an error
} else {
echo "###";
// transaction passed
}
echo "<pre>";
print_r($firstData);

Affiliate Window API integration in PHP

I am trying to write an application that integrates with the Affiliate Window API. The only problem I have is I have literally 0 experience in php and so find myself unable to debug even the most elementary of issues.
I downloaded the below code which is supposed to be a sample application. Unfortunately running it fails at the first hurdle:
Invalid argument supplied for foreach() in /Users/ravinthambapillai/Downloads/api.client/listmerchants.php on line 9
This is the error message I get when I run the below:
Can anyone help me with what I need to fix to get this right?
<?php
define('API', 'PS');
require_once('constants.inc.php');
require_once('classes/class.ClientFactory.php');
$oClient = ClientFactory::getClient(REDACTED, REDACTED, merchant);
$listmerchants = array('iCategoryId'=> 97, 'iMaxResult' => 10);
echo 'hello world';
$oResponse= $oClient->call('getMerchantList', $listmerchants);
foreach($oResponse->oMerchant as $details){
$name = $details->sName;
$strapline = $details->sStrapline;
$description = $details->sDescription;
$logo = $details->sLogoUrl;
$showurl = $details->sDisplayUrl;
$deeplink = $details->sClickThroughUrl;
$id = $details->iId;
if ($logo<>'') {
echo "<a href=".$deeplink." title='".$name."'><img src=".$logo.
" style='float:left; margin:5px;' alt='".$name.
" :: ".$strapline." :: ".$description." :: ".$showurl.
"' width=\"88\" height=\"31\" border=\"0\"></a>";
}
}
?>
Did you update the constants in constants.inc.php?
API_USERNAME needs to be set to your account ID, and API_PASSWORD needs to be set to your Affiliate API Password as seen at https://www.affiliatewindow.com/affiliates/accountdetails.php (when you're logged in)

YouTube PHP API - Getting status of previously uploaded video?

Just started digging into the YouTube PHP API and got the browser-based Zend upload script working. However, I can't find any documentation on how to retrieve the status of the video after it's been uploaded. The main reason I would need this is for error handling - I need to be able to know whether the video was approved by YouTube, since someone could technically upload an image or a file too large. I need to know that the vid was approved so that I know what message to display the end user when they return to the site (ie 'Your video is live' or 'Video upload failed').
The YouTube PHP browser-based upload returns a URL parameter status of 200 even if the format or size is incorrect, which is of course not helpful. Any ideas on how else to get this info from the YT object?
All in all, when a user returns to the site, I want to be able to create a YT object based on their specific video ID, and want to be able to confirm that it was not rejected. I'm using ClientLogin to initiate the YouTube obj:
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = 'myuser#gmail.com',
$password = 'mypassword',
$service = 'youtube',
$client = null,
$source = 'MySource', // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
Any thoughts?
Whew, finally found the answer to this after searching around and piecing together code for the last few days. After you create the $yt object, use the following to check the status:
$yt->setMajorProtocolVersion(2);
$youtubeEntry = $yt->getVideoEntry('YOUR_YOUTUBE_VID_ID', null, true);
if ($youtubeEntry->getControl()){
$control = $youtubeEntry->getControl();
$state = $control->getState()->getName();
}
Echoing out $state displays the string 'failed' if the video was not approved for whatever reason. Otherwise it's empty, which means it was approved and is good to go (Guessing the other state names would be: processing, rejected, failed, restricted, as Mient-jan Stelling suggested above).
Crazy how tough this answer was to put together for first-time YouTube API'ers. Solved! (Pats self on back)
Do you have a CallToken if so its pretty easy.
For this example i use Zend_Gdata_Youtube with Zend AuthSub.
WHen uploading your video you had a CallToken, With this call token you can access the status of the video.
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = 'myuser#gmail.com',
$password = 'mypassword',
$service = 'youtube',
$client = null,
$source = 'MySource', // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$youtube = new Zend_Gdata_YouTube( $httpClient, '', NULL, YOUTUBE_DEVELOPER_KEY );
$youtubeEntry = $youtube->getFullVideoEntry( 'ID_OF_YOUTUBE_MOVIE' );
// its the 11 digit id all youtube video's have
in $youtubeEntry all your data about the video is present
$state = $youtubeEntry->getVideoState();
if state is null then your video is available else make of state a string like this.
(string) $state->getName();
There are about 4 important state names. ( processing, rejected, failed, restricted)

Categories