I want to create php page for upload file into my dropbox.
I have got key and secret key from my dropbox account.
From here I got coding for dropbox but I did not get user id.
How can I get user id of dropbox.
https://www.dropbox.com/developers/core/start/php
list($accessToken, $dropboxUserId) = $webAuth->finish($authCode);
print "Access Token: " . $accessToken . "\n";
I assume you're using the standard PHP Dropbox SDK
$client = new Dropbox\Client($accessToken);
$info = $client->getAccountInfo();
echo $info["uid"];
<?php
error_reporting(E_ALL);
require_once("DropboxClient.php");
// you have to create an app at https://www.dropbox.com/developers/apps and enter details below:
$dropbox = new DropboxClient(array(
'app_key' => "",
'app_secret' => "",
'app_full_access' => true,
),'en');
handle_dropbox_auth($dropbox); // see below
// if there is no upload, show the form
if(empty($_FILES['the_upload'])) {
?>
<form enctype="multipart/form-data" method="POST" action="">
<p>
<label for="file">Upload File</label>
<input type="file" name="the_upload" />
</p>
<p><input type="submit" name="submit-btn" value="Upload!"></p>
</form>
<?php } else {
$upload_name = $_FILES["the_upload"]["name"];
echo "<pre>";
echo "\r\n\r\n<b>Uploading $upload_name:</b>\r\n";
$meta = $dropbox->UploadFile($_FILES["the_upload"]["tmp_name"], $upload_name);
print_r($meta);
echo "\r\n done!";
echo "</pre>";
}
to run before you have to authorized in dropbox apps
Related
I have previously used reCaptcha v1 and all was good until the Google changes a few years ago. I've now been asked to update a site, and am having some problems even with a simple bit of test code. The example below is a single index.php page, which traps for 'POST' when a form is submitted.
The reCaptch tick box appears, and allows a tick, but when the form is submitted I only get the 'Check the reCAPTCHA box' response. It looks like '$captcha=$_POST['g-recaptcha-response'];' is 'blank'. I am using the correct codes, and am getting stats on the reCaptcha admin page, but it is also reporting:
We detected that your site isn't verifying reCAPTCHA solutions. This is required for the proper use of reCAPTCHA on your site. Please see our developer site for more information.
What am I missing to verify?
<head>
<title>Test Contact Form</title>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
<body>
<?php
if (isset($_POST['submit'])) {
echo "submit detected..<br>";
$full_name;$email;$subject;$message;$captcha;
if(isset($_POST['full_name'])){
$full_name=$_POST['full_name'];
}if(isset($_POST['email'])){
$email=$_POST['email'];
}if(isset($_POST['subject'])){
$subject=$_POST['subject'];
}if(isset($_POST['message'])){
$message=$_POST['message'];
}if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo 'Check the reCAPTCHA box.';
echo $full_name . "<br>";
echo $email . "<br>";
echo $subject . "<br>";
echo $captcha . "<br>";
exit;
}
$secretKey = "6LemhA8aFAKEDRSKVHsecretVzN7Uv1BVQnpS-LwbjOo";
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?".$secretKey."&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
if($response.success==false)
{
echo 'You are a robot!';
}else
{
echo "I'd be sending an email to " . $email . "<br>";
echo "because the secret key" . $secretKey . "<br>";
echo "and the response " . $captcha . "<br>";
echo "matched.";
}
} ELSE {
?>
<div class="contact-form">
<h3>Send me your message v1</h3>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<div class="text-fields">
<span>Full Name *:</span>
<input name="full_name" type="text" class="text" value="Your Name">
</div>
<div class="text-fields">
<span>E-mail *:</span>
<input name="email" type="text" class="text" value="user#domain.com">
</div>
<div class="clearfix"> </div>
</div>
<div class="subject-field">
<span>Subject *:</span>
<input name="subject" type="text" class="text" value="Your Subject">
</div>
<div class="message-field">
<span>Message *:</span>
<textarea name="message"> </textarea>
</div>
<div class="g-recaptcha" data-sitekey="6LemhA8aFAKEJnoerEbOVLWEkeyYO3CcPo-HEIymP"></div>
<input type="submit" name="submit" value="Send" />
</form>
</div>
<?php } ?>
</body>
</html>
Captcha v2 Returns JSON Data (As seen on Official site) You should Decode json and then validate it.
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
'secret' => 'YOUR_SECRET',
'response' => $_POST["g-recaptcha-response"]
);
$options = array(
'http' => array (
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$verify = file_get_contents($url, false, $context);
$captcha_success=json_decode($verify);
if ($captcha_success->success==false) {
echo "<p>You are a bot! Go away!</p>";
} else if ($captcha_success->success==true) {
echo "<p>You are not not a bot!</p>";
}
there is also one problem in your code in " if($response.success==false)" you should write it as "if($response->success==false)"
I will comment after checking with your secrete id (Delete it afterword)
I suspect it's because you have an extra </div> after <div class="clearfix"> </div> – If you remove it, your code will probably work.
The extra closing div tag makes the browser believe that you're closing <div class="contact-form"> and since the <form> tag is inside of that, it tries fix your HTML and close that as well. However, that means that the remaining fields (subject, message) and reCAPTCHA are placed outside the <form>. reCAPTCHA only sets g-recaptcha-response if it's actually inside a <form>, no matter if the user successfully completes it or not.
An additional adjustment
You also need to decode the JSON returned from https://www.google.com/recaptcha/api/siteverify like so:
$response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?".$secretKey."&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
if($response["success"]==false)
I want to create trello teams automatically via an html form from my website.
I wrote a php script that seems to work. For example I can get list of boards or create a new board. But it does not works to create teams.
HTML CODE
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="api_method.php" method="post">
Project Name:<br>
<input type="text" name="projectName" value="board_test">
<br><br>
<input type="submit" value="Submit">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a page called "api_method.php".</p>
</body>
</html>
I then use a php script to create the new board:
<?php
require("trello_api.php");
$key = 'mykey';
$token = 'mytoken';
$trello = new trello_api($key, $token);
$data = $trello->request('GET', ('member/me/boards'));
$obj = array('name' => $_POST['projectName']);
$trello->request('POST', ('/boards'),$obj);
echo "Board name: " . $data[0]->name . "\n \n";
echo "New board: " . $_POST['projectName'];
?>
So that works perfectly but not when I try to do the same thing with "organizations" it doesn't work
$trello->request('POST', ('/organizations'),$obj);
Can you please help me.
I found the solution, I had to use the option "displayName" instead of "name"
<?php
require("trello_api.php");
$key = 'myKey';
$token = 'myToken';
$trello = new trello_api($key, $token);
$data = $trello->request('GET', ('member/me/boards'));
$obj = array('displayName' => $_POST['projectName']);
$trello->request('POST', ('/organizations'),$obj);
echo "Board name: " . $data[0]->name . "\n \n";
echo "New board: " . $_POST['projectName'];
?>
I have been trying to make Twitter reply code using PHP and it didn't work. When I run it it just post it as a tweet without the reply to the tweet id.
in_reply_to_status_id doesn't work when I run the code.
is there any solution?
<form action="<?php echo $PHP_SELF;?>" method="post">
<input type="submit" name="do"value="do"></input>
<input type="text" name="tweetid" placeholder="tweet id"></input>
<input type="text" name="message" placeholder="message"></input>
</form>
<?php
require_once('twitteroauth.php');
$connect=mysql_connect ("localhost","___","___");
mysql_select_db ("___");
if(isset($connect)){
$do=$_POST ['do'];
$message=$_POST ['message'];
$tweetid=$_POST ['tweetid'];
$consumerKey = '___';
$consumerSecret = '___';
$accessToken= '___';
$accessTokenSecret= '___';
if(isset($do)){
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken,$accessTokenSecret);
$tt=$tweet->post('statuses/update', array ('status'=>$message , 'in_reply_to_status_id' =>$tweetid));
}}
else {
print "error";
}
mysql_close ();
?>
I'm attempting to upload a video to YouTube via the API using Zend_Gdata (Zend Framework 1.12.0). I had no problems getting direct upload to work, but browser-based upload always gives me a 400 - INVALID TOKEN error. I'm pretty sure I must be missing something vital but small enough to not notice it.
There are two files involved in this:
index.php
<?php
$youTubeAPIKey = '<API_Key>';
$username = '<user>';
$password = '<pass>';
set_include_path(get_include_path().PATH_SEPARATOR.__DIR__."/vendor");
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
try
{
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username,
$password,
$service = 'youtube',
$client = null,
$source = 'BrowserUploaderTest', // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$yt = new Zend_Gdata_YouTube($httpClient, "browser upload test", "Test version 0.1", $youTubeAPIKey);
$videoEntry = new Zend_Gdata_YouTube_VideoEntry();
$videoEntry->setVideoTitle("Test movie");
$videoEntry->setVideoDescription("This is a test movie");
$videoEntry->setVideoPrivate();
// #todo This must be a valid YouTube category, how to get a list of valid categories?
$videoEntry->setVideoCategory('Autos');
$videoEntry->setVideoTags('cars, funny');
// Get an upload token
$tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
$tokenArray = $yt->getFormUploadToken($videoEntry, $tokenHandlerUrl);
$token = $tokenArray['token'];
$url = $tokenArray['url'];
// print "Token value: {$tokenArray['token']}\n url: {$tokenArray['url']}\n";
$nextUrl = "http://" . $_SERVER['HTTP_HOST'] . "/uploadDone.php";
}
catch (Zend_Gdata_App_HttpException $httpException)
{
echo $httpException->getRawResponseBody();
}
catch (Zend_Gdata_App_Exception $e) {
echo $e->getMessage();
}
catch (Exception $e)
{
print $e->getTraceAsString();
}
?><!DOCTYPE html>
<html>
<head>
<title>Testing Youtube upload</title>
</head>
<body>
<table>
<tr>
<td>
Url:
</td>
<td>
<?= $url ?>
</td>
</tr>
<tr>
<td>
Token:
</td>
<td>
<?= $token ?>
</td>
</tr>
</table>
<form action="<?= $url ?>.?nexturl=<?= urlencode($nextUrl) ?>" enctype="multipart/form-data" method="post">
<input name="token" type="hidden" value="<?= $token ?>" />
<input name="file" type="file" />
<input type="submit" value="Upload file" />
</form>
</body>
</html>
and uploadDone.php
<?php
print nl2br(print_r($_GET, true));
print nl2br(print_r($_POST, true));
I've searched both on Stack Overflow and spent a couple of hours searching on Google but not found anything that solves it which leads me to believe I'm missing something dead simple. Any help would be appreciated.
A note:
This code is only to test the API usage and is taken mostly from Google's Developer's guide (https://developers.google.com/youtube/2.0/developers_guide_php#Browser_based_Upload) and with a little help from the Yii framework documentation (http://www.yiiframework.com/wiki/375/youtube-api-v2-0-browser-based-uploading/). The production code will be rewritten in a more structured manner but that's not important at the moment.
Your action="<?= $url ?>.?nexturl=<?= urlencode($nextUrl) ?>" looks suspicious; is that an errant . character in there right after your $url variable gets evaluated, messing up the URL?
I use my recently develop fb app to post on my wall and its shows the following error
Uncaught OAuthException: (#100) picture URL is not properly formatted thrown in
you can also see this directly *https://apps.facebook.com/hack-proof_pages/1gp.html
using two files "1gp.html" and "gp1.php"
1gp.html code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="gp1.php">
<p>message
<textarea style="width:300px; height:50px;" name="message1"></textarea>
</p>
<p>link
<input type="text" style="width:300px;" name="link1" />
</p>
<p>
Picture
<input type="text" name="picture1" />
</p>
<p>
name
<input type="text" style="width:300px;" name="name1" />
</p>
<p>
Caption
<input type="text" style="width:300px;" name="caption1" />
</p>
<p>Description
<textarea style="width:300px; height:50px;" name="description1"></textarea>
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>
gp1.php code
<?php
require_once 'library/facebook.php';
// Create our Application instance.
$facebook = new Facebook(array(
'appId' => '149865361795547',
'secret' => 'shhhh seceret :)',
'cookie' => true,
));
$app_id = '149865361795547';
$canvas_page = "https://apps.facebook.com/hack-proof_pages/gp1.php";
//get data for post
$message1 = $_POST['message1'];
$picture1 = $_POST['picture1'];
$name1 = $_POST['name1'];
$link1 = $_POST['link1'];
$caption1 = $_POST['caption1'];
$description1 = $_POST['description1'];
// compile the post for for user
$WallPost = array(
'message' => $message1,
'link' => $link1,
'picture' => $picture1,
'name' => $name1,
'caption' => $caption1); // you can also use 'picture', 'link', 'name', 'caption', 'description', 'source'....
//http://developers.facebook.com/docs/reference/api/
$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page) . ("&scope=email,read_stream,publish_stream,offline_access,publish_actions,manage_pages,user_groups&response_type=token");
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["user_id"])) {
echo("<script> top.location.href='" . $auth_url . "'</script>");
} else {
//getting the userid and some other data for verification
//get the user id
$UserId = $data["user_id"];
echo 'UserId;' . $UserId;
//get the user access token
$atoken = $facebook->getAccessToken();
echo "</br>" . 'User Access_Token:' . $atoken;
//set default access token and profile
//$facebook->setAccessToken($atoken);
//$user_profile = $facebook->api('/me');
//get the user name and email
$user_id = $facebook->getUser();
$user_profile = $facebook->api('/me','GET');
$user_name = $user_profile['name'];
echo "Name: " . $user_name;
$user_email = $user_profile['email'];
echo "email: " . $user_email;
// post to user wall
$response = $facebook->api('/me' . '/feed','POST',$WallPost);
//posting to groups wall with sleeping time support poster.xls
}
?>
*Note: my app use self signed certificate SSL so that if you want to test this above URL you need to allow my site and store its certificate and one more info that sometimes google chrome shows error due to google chrome one weak point that chrome needs to store self signed certificate in internet explorer means if you want to check this in chrome you need to first open this site in internet explorer and allow my site self signed certificate and store permanently so that its also work in chrome
Please check your picture url, you need to give the full url of the photo not the relative url and facebook should be able to access the picture url, i.e. it should not be of your locally hosted application, try placing a fully qualified sample url of any picture in ur code and check.