how to resolve OAuthException: (#100) - php

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.

Related

Create a team/organizations via trello api

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'];
?>

Tweet image with Twitter API not posting

I'm trying to create a simple app that sends a tweet of an image with a caption upon form submission. The test appears to be working at http://5starvintage.com/tweet/, but the tweet is never posted.
Any idea as to why the submitted tweet isn't posting?
Here's the form...
<form method="post" action="<?php echo bloginfo('template_directory');?>/tweet/start.php" enctype="multipart/form-data" onsubmit="FSV.initTweetValidate()" >
<div id="tweetWrap" class="clearfix">
<div id="imageDrop">
<span class="desc">Upload Image</span>
<input type="file" name="img" id="img"/>
</div>
<div id="tweetText">
<textarea type="text" name="txt" id="txt" maxlength="140" onkeyup="FSV.initCountChar(this)" placeholder="#5StarVintage..."></textarea>
<div id="charNum">140</div>
</div>
</div>
<input type="submit" name="sub" class="tweet" id="sub" value="Submit"/>
</form>
Here is the form action code, start.php..
<?php
require './config.php';
require './tmhOAuth.php';
/////// upload the photo
$img = $_FILES["img"]["name"];
move_uploaded_file($_FILES["img"]["tmp_name"],$img);
////////// generate *temp* access token and save it in cookie for callback page
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => API_KEY,
'consumer_secret' => API_SEC,
'curl_ssl_verifypeer' => false
));
$tmhOAuth->request('POST', $tmhOAuth->url('oauth/request_token', ''));
$response = $tmhOAuth->extract_params($tmhOAuth->response["response"]);
$txt = $_POST['txt'];
$temp_token = $response['oauth_token'];
$temp_secret = $response['oauth_token_secret'];
$time = $_SERVER['REQUEST_TIME'];
setcookie("Temp_Token", $temp_token, $time + 3600 * 30, '/tweet/');
setcookie("Temp_Secret", $temp_secret, $time + 3600 * 30, '/tweet/');
setcookie("Img_Url", $img, $time + 3600 * 30, '/tweet/');
setcookie("Tweet_Txt", $txt, $time + 3600 * 30, '/tweet/');
///////// redirect to twitter page for user authincation
$url = $tmhOAuth->url("oauth/authorize", "") . '?oauth_token=' . $temp_token;
header("Location:".$url);
// after user give the required authrization he will be redirect to callback.php on your serve
exit();
?>
Here's the callback.php..
<?php
require './config.php';
require './tmhOAuth.php';
require './tmhUtilities.php';
/// retrive temp access token from cookie
$token = $_COOKIE['Temp_Token'];
$secret = $_COOKIE['Temp_Secret'];
$img = $_COOKIE['Img_Url'];
$txt = $_COOKIE['Tweet_Txt'];
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => API_KEY,
'consumer_secret' => API_SEC,
'user_token' => $token,
'user_secret' => $secret,
'curl_ssl_verifypeer' => false
));
/// Ask Twitter for correct access token
$tmhOAuth->request("POST", $tmhOAuth->url("oauth/access_token", ""), array(
// pass the oauth_verifier received from Twitter
'oauth_verifier' => $_GET["oauth_verifier"]
));
$response = $tmhOAuth->extract_params($tmhOAuth->response["response"]);
$tmhOAuth->config["user_token"] = $response['oauth_token'];
$tmhOAuth->config["user_secret"] = $response['oauth_token_secret'];
$img = './'.$img;
$code = $tmhOAuth->request('POST', 'https://api.twitter.com/1.1/statuses/update_with_media.json',
array(
'media[]' => "#{$img}",
'status' => "$txt" // Don't give up..
),
true, // use auth
true // multipart
);
if ($code == 200){
tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
echo '<h1>Your image tweet has been sent successfully</h1>';
}else{
// display the error
tmhUtilities::pr($tmhOAuth->response['response']);
return tmhUtilities;
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tweet an Image</title>
</head>
<body>
</body>

php facebook event rsvp

I have an event on facebook I would like to rsvp attending to. I would like to rsvp with a link, all the examples I have found for rsvping were done with forms. I have the rsvp_event permission and an active access_token. The actual problem I am facing is redirecting after a successful http post.
<?php
$redirect_uri = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$access_token = "ACCESS_TOKEN";
$eid = "EVENT_ID";
$rsvp_to_event = "https://graph.facebook.com/$eid/attending?method=post&access_token=$access_token&redirect_uri=$redirect_uri";
?>
Join
Clicking the 'Join' link will rsvp to the event, but leaves me on a page displaying true. Any ideas to get the page to redirect after a successful rsvp?
Thank you.
You have to query that URL using cURL or file_get_contents(), here's an example from my tutorial:
<?php
$app_id = "APP_ID";
$app_secret = "APP_SECRET";
$my_url = "REDIRECT_URI";
$event_id = "EVENT_ID";
$rsvp_status = "";
$code = $_REQUEST["code"];
if(empty($code)) {
$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&scope=rsvp_event";
echo("<script>top.location.href='" . $auth_url . "'</script>");
}
$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$access_token = file_get_contents($token_url);
if( isset($_POST['rsvp']) ) {
// Form submitted, call the Graph API to RSVP to the event
$event_rsvp = "https://graph.facebook.com/$event_id/{$_POST['rsvp']}?method=post&" . $access_token;
$rsvped = json_decode(file_get_contents($event_rsvp));
if($rsvped) {
$msg = "Your RSVP status is now <strong>{$_POST['rsvp']}</strong>";
$rsvp_status = $_POST['rsvp'];
}
}
if( !$rsvp_status ) {
$query = "SELECT rsvp_status FROM event_member WHERE eid=$event_id AND uid=me()";
$fql_url = "https://api.facebook.com/method/fql.query?"
. "query=" . urlencode($query)
. "&format=json"
. "&" . $access_token;
$fql_resp = json_decode(file_get_contents($fql_url));
$rsvp_status = $fql_resp[0]->rsvp_status;
}
?>
<!doctype html>
<html>
<head>
<title>Create An Event</title>
<style>
label {float: left; width: 100px;}
input[type=text],textarea {width: 210px;}
#msg {border: 1px solid #000; padding: 5px; color: red;}
</style>
</head>
<body>
<?php if( isset($msg) ) { ?>
<p id="msg"><?php echo $msg; ?></p>
<?php } ?>
<form action="" method="post">
<p>
<label for="privacy_type">RSVP:</label>
<input type="radio" name="rsvp" value="attending" <?php if($rsvp_status==="attending") echo "checked='checked'"; ?>/>Attending
<input type="radio" name="rsvp" value="maybe" <?php if($rsvp_status==="maybe" || $rsvp_status==="unsure") echo "checked='checked'"; ?>/>Maybe
<input type="radio" name="rsvp" value="declined" <?php if($rsvp_status==="declined") echo "checked='checked'"; ?>/>Not Attending
</p>
<p><input type="submit" value="RSVP to this event" /></p>
</form>
</body>
</html>
You should be looking at:
if( isset($_POST['rsvp']) ) {
// Form submitted, call the Graph API to RSVP to the event
$event_rsvp = "https://graph.facebook.com/$event_id/{$_POST['rsvp']}?method=post&" . $access_token;
$rsvped = json_decode(file_get_contents($event_rsvp));
if($rsvped) {
$msg = "Your RSVP status is now <strong>{$_POST['rsvp']}</strong>";
$rsvp_status = $_POST['rsvp'];
}
}
The above tutorial consist of HTML form where the user can choose his status.
Most graph api endpoints are not designed to be called directly with your user's browser but to call them from your backend code (authentication related ones could be exception).
Try using the offical php sdk for sending those requests from your php page, or just use the curl extension or file_get_contents on these endpoints from your php script and redirect the user yourself.

Getting TOKEN_INVALID when uploading to YouTube

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?

flickr.photos.search

I would like to ask for help. I got this homework to create a class in PHP with search method which returns 50 pictures from Flickr, but without use of official PHP Flickr libraries... Anyway with help of google I wrote following code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
class Flickr {
private $apiKey = 'aba429532a6606f2ee35e3f47a300716';
public function search($query = null) {
$search = 'http://flickr.com/services/rest/?method=flickr.photos.search&api_key=' . $this->apiKey . '&text=' . urlencode($query) . '&per_page=50&format=php_serial';
$result = file_get_contents($search);
$result = unserialize($result);
return $result;
}
}
?>
<form action="index.php" method="get">
<input type="text" name="text1" /><br />
<input type="submit" name="submit1" value="Send" /><br />
</form>
<?php
if(isset($_GET["submit1"])) {
$Flickr = new Flickr;
$data = $Flickr->search($_GET["text1"]);
foreach($data['photos']['photo'] as $photo) {
echo '<img src="http://farm' . $photo["farm"] . '.static.flickr.com/' . $photo["server"] . '/' . $photo["id"] . '_' . $photo["secret"] . '.jpg">';
}
}
?>
</body>
</html>
That code does what I need, but I am not sure whether I can use flickr.photos.search, so I was wondering if there is a way to avoid using flickr.photos.search.
You could just request http://www.flickr.com/search/?q={work_by_witch_you_search}&z=m pictures from here with curl and just parse received page. Then you definitely wount use anything even close to Flickr API.

Categories