i am using a twitter script to post messages to the twitter wall from a html form
see here:
<form name="csp_post" action="/test.php" method="post" >
<textarea name="text" id="text" rows="3" cols="64" ></textarea>
<input type="hidden" name="action" value="post">
<?php session_start();
include 'twitter-oauth/lib/EpiCurl.php';
include 'twitter-oauth/lib/EpiOAuth.php';
include 'twitter-oauth/lib/EpiTwitter.php';
include 'twitter-oauth/lib/secret.php';
$twitterObj = new EpiTwitter($consumer_key, $consumer_secret);
if(isset($_SESSION['oauth_token'])){
$oauth_token = $_SESSION['oauth_token'];
}
else {
$oauth_token = $_GET['oauth_token'];
$_SESSION['oauth_token']=$_GET['oauth_token'];
}
$oauth_token = $_GET['oauth_token'];
if($oauth_token == '')
{
$url = $twitterObj->getAuthorizationUrl();
echo "<div style='width:auto;margin-top:10px;margin-left:10px;margin-right:auto'>";
echo "<a href='$url'>Sign In with Twitter to post Comments</a>";
echo "</div>";
}
else
{
echo "<div style='width:auto;margin-top:10px;margin-left:10px;margin-right:auto'>";
echo "Your comments are now being posted on Twitter";
echo "</div>";
$twitterObj->setToken($_GET['oauth_token']);
$token = $twitterObj->getAccessToken();
$twitterObj->setToken($token->oauth_token, $token->oauth_token_secret);
$_SESSION['ot'] = $token->oauth_token;
$_SESSION['ots'] = $token->oauth_token_secret;
$twitterInfo= $twitterObj->get_accountVerify_credentials();
$twitterInfo->response;
$username = $twitterInfo->screen_name;
$profilepic = $twitterInfo->profile_image_url;
}
if(isset($_POST['cssp']))
{
$msg = $_REQUEST['text'];
$twitterObj->setToken($_SESSION['ot'], $_SESSION['ots']);
$update_status = $twitterObj->post_statusesUpdate(array('status' => $msg));
$temp = $update_status->response;
echo "<div align='center'>Updated your Timeline Successfully .</div>";
}
?>
<input type='image' src='../images/123.gif' rel='submit' border='0' value='Tweet' name='cssp' id='cssp' alt='Share'/>
</form>
so the twitter will grab whatever i post into the text area and post it onto the wall.
i would like to do the same with facebook. I know there are applications that can do the same thing, but the ones i found uses a different textarea, and i want to use the one i have already.
any ideas?
Thanks
You can use the Facebook Graph API for this (documentation: http://developers.facebook.com/docs/reference/api/), specifically the following function:
http://developers.facebook.com/docs/reference/api/post/
Read the bottom of the page, the block named Publishing, this should do what you want.
To authenticate using the account to your choice, you will have to use OAuth (http://developers.facebook.com/docs/authentication/); this is rather complex so I would highly recommend using a library for this, preferably Facebooks own PHP Library: https://github.com/facebook/php-sdk/
Related
I wanna get a functional download/videostreaming link, i'm trying this through
Openload and pCloud API, but I always getting error when I put my script in anywhere outside my localhost.
My pCloud code is:
<?
ini_set('display_errors','0');
echo '<form method="POST" enctype="multipart/form-data" id="add-row-form" action="">';
echo "<input type='text' value='XZ1Ix57ZIVJU5FGmV8bkvWwukuJ0JBkIKJzX' placeholder='ID da Série' name='tvshowid'></input>";
echo "<button name='ok' type='submit'>Tudo certo</button>";
echo '</form>';
$query = $_POST['tvshowid'];
$lang = $_POST['lang'];
if(isset($_POST['ok'])) {
$postdata = file_get_contents("https://api.pcloud.com/getpublinkdownload?code=". $query);
$request = json_decode($postdata);
print_r($request);
$theData = $request;
$host = $theData->hosts[rand(0,1)];
$path = $theData->path;
$vlink = 'https://'.$host. $path;
echo '<div>';
echo '<video width="30%" height="auto" controls autoplay>
<source src="'.$vlink.'" type="video/mp4">
</video>';
echo "</div>";
}
?>
Preview
Always when i try to generate a link, it says "This link was generated for another IP address. Try previous step again."
The question is: How can I get data from a JSON through my user's IP or server adrres and not by my server address (as has been happening), so that the video link is valid?
i'm trying to display some custom facebook feeds on my website from a facebook fan page.
This is a summary sample of the php I used, and it works fine.
[...html code...]
// include the facebook sdk
require_once('resources/facebook-php-sdk-master/src/facebook.php');
// connect to app
$config = array();
$config['appId'] = 'MY_APP_ID';
$config['secret'] = 'MY_SECRET_CODE';
$config['fileUpload'] = false; // optional
// instantiate
$facebook = new Facebook($config);
// set page id
$pageid = "MY_PAGE_ID";
// access to the graph, starting with the feed
$pagefeed = $facebook->api("/" . $pageid . "/feed");
[...html code...]
$i = 0;
foreach($pagefeed['data'] as $post) {
// check if post type is a photo and catch the various part of the graph
if ($post['type'] == 'photo') {
//grab the thumbnail url in the graph
$picture_url = $post['picture'];
//get true sized photo by manipulating its url
$picture_url_big = str_replace("s130x130/","", $picture_url);
echo "<p><img class=\"img-icon\" src=\"" . $post['icon'] . "\"></p>";
echo "<h2 class=\"data-post\">" . date("j-n-Y", (strtotime($post['created_time']))) . "</h2>";
//displaying the photo
echo "<div class=\"img-thumb\"><img src=\"" . $picture_url_big . "\"></div>";
echo "<p class=\"manda-a-capo\"></p>";
if (empty($post['story']) === false) {
echo "<p>" . $post['story'] . "</p>";
} elseif (empty($post['message']) === false) {
echo "<p>" . $post['message'] . "</p>";
}
echo "<p><u><b>Vedi foto</b></u></p>";
echo "<p class=\"manda-a-capo\"></p>";
if ($post['shares']['count'] != "") {
echo "<p class=\"manda-a-capo share-num\">" . $post['shares']['count'] . " condivisioni.</p>";
}
}
$i++;
}
[...other code...]
The facebook graph contains only the thumb url of the photos, that is 130x130px. I discovered that some thumbs have an "/s130x130/" parameter in the url and, if you delete this parameter, you get the photo in its actual size.
So this explains this part of code (as above):
//grab the thumbnail url in the graph
$picture_url = $post['picture'];
//get true sized photo by manipulating its url
$picture_url_big = str_replace("s130x130/","", $picture_url);
//then displaying the photo
echo "<div class=\"img-thumb\"><img src=\"" . $picture_url_big . "\"></div>";
Unfortunately I noticed that not all photos from the page have this parameter and some of them have even a different url structure.
So the final result is that I can reach only few photos in their actual size, others remain a broken link.
Is there a way to manipulate the url to get all the photos in their own actual size?
Any advices?
Thanks.
P.S.
Here's the php to view the fb graph:
<?php
echo "<pre>";
print_r($pagefeed);
echo "</pre>";
?>
I found a temporary solution. In order to display the missing links I've added a php function that checks if the image url exist or not.
function checkRemoteFile($picture_url_big)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$picture_url_big);
// don't download content
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(curl_exec($ch)!==FALSE)
{
return true;
}
else
{
return false;
}
}
And a control just above the "echo"
if (checkRemoteFile($picture_url_big)) {
//echo "image exist ";
$check = true;
$picture_url_big;
} else {
//echo "image does not exist ";
$check = false;
$picture_url_big = $picture_url;
}
A friend of mine wrote this script, displaying the 20 most recent instagram images, and I was wondering, how can I change the amount of images it grabs to maybe, 6?
<?PHP
$token = 'token';
$username = 'username';
$userInfo = json_decode(file_get_contents('https://api.instagram.com/v1/users/search?q='.$username.'&access_token='.$token));
if($userInfo->meta->code==200){
$photoData = json_decode(file_get_contents('https://api.instagram.com/v1/users/'.$userInfo->data[0]->id.'/media/recent/?access_token='.$token));
if($photoData->meta->code==200){ ?>
<?PHP foreach($photoData->data as $img){
echo '<img src="'.$img->images->thumbnail->url.'">';
} ?>
<?PHP } // If
} // If
?>
Now, the script is functional now because I've been working on it all day, but I'm not sure how to change how many it sends out.
Also, would any of you know how to style this? I already have the CSS done for it, but whenever I try it, it doesn't work correctly.
And, would you know how to get the description of the photo using the API?
Thank you in advance :-)
You need to use Instagram's count= url parameter when requesting data from their endpoints.
For example: https://api.instagram.com/v1/users/search?count=6
Or in your code:
<?PHP
$token = 'token';
$username = 'username';
$userInfo = json_decode(file_get_contents('https://api.instagram.com/v1/users/search?count=6&q='.$username.'&access_token='.$token));
if($userInfo->meta->code==200){
$photoData = json_decode(file_get_contents('https://api.instagram.com/v1/users/'.$userInfo->data[0]->id.'/media/recent/?count=6&access_token='.$token));
if($photoData->meta->code==200){ ?>
<?PHP foreach($photoData->data as $img){
echo '<img src="'.$img->images->thumbnail->url.'">';
} ?>
<?PHP } // If
} // If
?>
Pseudo example for styling. You'll need to figure out the css styles for that, but shouldn't be to difficult.
<div class='myBorder'>
<img url=$img->link />
<div class='myCaption'>$img->caption->text</div>
</div>
To get the description
if (isset($img->caption)) {
if (get_magic_quotes_gpc()) {
$title = stripslashes($img->caption->text);
} else {
$title = $img->caption->text;
}
}
i want the value of $code variable to get on my other page--- captcha.php.
captcha_image.php
$captcha = new CaptchaCode(); //class defined in captcha_code.php
$code = str_encrypt($captcha->generateCode(6)); //function defined in captcha_code.php
$captcha1 = new CaptchaImages();
$captcha1-> GenerateImage($width,$height,str_decrypt($code));
captcha.php
<img style="cursor: pointer;width: 50px;height: 50px;" src="refresh.png" onclick="refresh_captcha();"/>
<input type="hidden" name="security_check" value="<?php echo $code; ?>"> // want value of $code here
<script type="text/javascript">
function refresh_captcha()
{
var img = document.getElementById('captcha_img');
img.src = 'captcha_images.php';
jQuery("#captcha_img").attr("src",img.src);
}
</script>
I cant include captcha_images.php file in my code and even dont want it to be done using sessions, tried that way.If anyone has a solution for this, please help me to solve this issue.
Better solution is save code into SESSION.
For example:
captcha_image.php:
session_start();
$captcha = new CaptchaCode();
$code = $captcha->generateCode(6);
$captcha1 = new CaptchaImages();
$captcha1-> GenerateImage($width,$height,$code);
$_SESSION["captchacode"] = $code;
And check correctness after submit of the form:
session_start();
...
if($_SESSION["captchacode"]!=$_POST["security_check"]){
echo "Wrong captcha!";
}else{
// captcha is correct, process the form
}
If you cannot use cookies and session, you cannot get information from captcha_image.php which returns only image. You must generate information in else request, for example:
<img id="captcha_img" src="captcha_images.php?encoded_code=<?php echo $code ?>" onclick="refresh_captcha();"/>
<input type="hidden" id="captcha_hidden" name="security_check" value="<?php echo $code ?>">
<script type="text/javascript">
function refresh_captcha()
{
// generate_captcha.php returns only encoded captcha
$.get('generate_captcha.php', function(encoded_code) {
$('#captcha_hidden').val(encoded_code);
$('#captcha_img').attr("src","captcha_images.php?encoded_code="+encoded_code);
});
}
</script>
Here generate_captcha.php returns encoded captcha, captcha_images.php doesnt generate code, only decode code from hims parameter encoded_code and this code is also inserted into hidden.
I am trying to:
Retrieve a friend list from a user with the friend information:
Location
Education
Name
Profile picture
The problem is the standard permissions given only has friend profile picture and name. I used this to get the other information:
$params = array(
'scope' => 'email, friends_likes, user_about_me, friends_about_me, friends_location, friends_website, friends_work_history, friends_education_history'
);
$loginUrl = $facebook->getLoginUrl($params);
}
So now when I log in on my page, Facebook asks me if I'm willing to give those permissions to the application, so that is a good sign.
The problem is I'm still not able to figure out how to get the information. When I try and do
print_r($friends);
or
print_r($friends["data");
I still just get an array with name and ID.
Why am I not seeing the extra information?
This is not the full code, but a lot of it (most came from the example.php from the main Facebook GitHub account):
<?php
if ($user):
echo "Name: " . $user_profile['name']; ?> <br />
<?php echo "Location: " . $user_profile['location']['name']; ?> <br />
<?php echo "Bio: " . $user_profile['bio']; ?> <br />
<?php
foreach($user_profile['work'] as $work) {
echo "Work: " . $work['employer']['name'];?><br />
<?php echo "Position: " . $work['position']['name'];?><br />
<?php
}
?>
<img src="https://graph.facebook.com/<?php echo $user; ?>/picture?type=large">
<h3>Your User Object (/me)</h3>
<pre><?php
print_r($friends);
?></pre>
<?php
echo '<ul>';
foreach ($friends["data"] as $value) {
echo '<li>';
echo '<div class="pic">';
echo '<img src="https://graph.facebook.com/' . $value["id"] . '/picture?type=large"/>';
echo '</div>';
echo '<div class="picName">'.$value["name"].'</div>';
echo '<div class="location">'.$value["location"]["name"];
echo '<div class="bio">'.$value["bio"];
echo '</div>';
echo '</li>';
}
echo '</ul>';
?>
The API call (note I made the $permissions just for testing to be sure I was getting it, and they are showing up).
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
$permissions = $facebook->api('/me/permissions');
$friends = $facebook->api('/me/friends');
}
catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
Your API call to /me/friends is incorrect. You need to do something like:
$friends = $facebook->api('me/friends?fields=birthday,location,about...');
You need to add in the extra fields you require as parameters in the API call. I've added a few in the above example, but you will need to add the remaining ones.