User Credentials Validation Error and Update With Media Error using
CodeBird PHP
i want to check user credentials after user login in a form, then if
username and password correct, user will redirected to upload.php page,
and after upload an image and a status, image and status will post on user
twit
and here's my code
<h2>Verifikasi ID Twitter...</h2>
/*verification of user credentials
after validation of username and password success, redirect to upload
image and status page
but if validation of username and password fail, back to login page
*/
<?php
require_once('codebird.php');
$cb = new \Codebird\Codebird;
$id = $_POST['id'];
$pass = $_POST['pass'];
//if($_POST['loginTwitter'] == "Submit"){
//if(isset($_POST['loginTwitter'])){
if(isset($id) && isset($pass)){
//cek bener apa engga nya
//if($_POST['id'] == '' || $_POST['pass'] == ''){ header('login.php'); }
$cb::setConsumerKey('somekey', 'somekeysecret');
$cb::getInstance();
$cb->setToken('tokenaccess', 'tokenaccesssecret');
$code = $cb->account_verifyCredentials();
if($code == 200){
//$reply = $cb->oauth2_token();
//$bearer_token = $reply->access_token;
header('upload.php');
}
else{ header('login.php'); }
//echo "Redirect to Upload Image...."; for($i = 0; $i <= 20000000;
$i++); header('upload.php');
}
else{
echo "<br />";
echo "<h3>Something went wrong... Please Check Again Your
Credentials</h3>";
}
?>
and here's the post.php page (for posting image and status to user twit
using update_with_media API
<div id="photo_tweet">
<h2>Photo Tweet</h2>
<br />
<?php require_once('codebird.php'); ?>
<?php
function redirectToUpload(){
echo "Redirect...";
for($i = 0; $i <= 20000000; $i++);
header('upload.php');
}
?>
<?php
$imgExt = array("jpeg", "jpg", "png");
$currImgExt = end( explode(".", $_FILES["file"]["name"]) );
if($_POST['uploadTwit'] == "Submit"){
if ((($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png") || $_POST['status'] == '')
&& ($_FILES["file"]["size"] < 20000)
&& in_array($currImgExt, $imgExt))
{
if ($_FILES["file"]["error"] > 0){
echo "Error: " . $_FILES["file"]["error"] . "<br>";
redirectToUpload();
}
else{
$params = array(
'status' => $_POST['status'],
'media[]' => $_FILES["file"]["name"]
);
/*
$data_user = array(
'user_id' => ,
'screen_name' =>
);
*/
$reply = $cb->statuses_updateWithMedia($params);
}
}
}
else { echo "Invalid Image File or Invalid File Size or Twit cannot
empty! Please check agian your image file before proceed!";
redirectToUpload(); }
?>
<p>You Just Succeed Post image and status!</p>
</div>
No comments:
Post a Comment