Tumblr API get current AVATAR URL - tumblr

Everyone knows? about avatar url in tumblr api / read / json?
like for example the facebook?
http://graph.facebook.com/[your facebook id]/picture?type=normal
<?php
$tumblog = 'natadec0c0'; // change to your username
// if your Tumblog is self hosted, you need to change the base url to the location of your tumblog
$baseurl = 'http://' . $tumblog . '.tumblr.com';
$request = $baseurl . '/api/read/json';
$ci = curl_init($request);
curl_setopt($ci,CURLOPT_RETURNTRANSFER, TRUE);
$input = curl_exec($ci);
curl_close($ci);
// Tumblr JSON doesn't come in standard form, some str replace needed
$input = str_replace('var tumblr_api_read = ','',$input);
$input = str_replace(';','',$input);
// parameter 'true' is necessary for output as PHP array
$value = json_decode($input,true);
$content = $value['posts'];
$blogInfo = $value['tumblelog'];
// the number of items you want to display
$item = 10;
// Echo the blog info
echo "<h3>" . $blogInfo['title'] . "</h3>\n";
echo "<h4>" . $blogInfo['picture'] . "</h4>\n<hr />\n";
?>
how to append my current avatar?

A better solution for this is to put the Avatar api in an img tag.
api.tumblr.com/v2/blog/{base-hostname}/avatar[/size]
example: <img src='http://api.tumblr.com/v2/blog/myreallycoolblog.tumblr.com/avatar/48'/>
So as long as you have the blogname, you can display the avatar.

I guess you have to use
GET http://www.tumblr.com/api/authenticate?email=user#example.com&password=12345
to get the avatar of the user. The sample response for mine is
<tumblr version="1.0">
<user default-post-format="html" can-upload-audio="1" can-upload-aiff="1" can-ask-question="1" can-upload-video="1" max-video-bytes-uploaded="26214400" liked-post-count="134"/>
<tumblelog title="ABNKKPGPiCTuReNPLaKo?!" is-admin="1" posts="301" twitter-enabled="0" draft-count="0" messages-count="0" queue-count="" name="arvn" url="http://arvn.tumblr.com/" type="public" followers="17" avatar-url="http://28.media.tumblr.com/avatar_b1786ec9e62d_128.png" is-primary="yes" backup-post-limit="30000"/>
<tumblelog title="i kras yu." is-admin="1" posts="1" twitter-enabled="0" draft-count="0" messages-count="0" queue-count="" name="ikrasyu" url="http://ikrasyu.tumblr.com/" type="public" followers="2" avatar-url="http://25.media.tumblr.com/avatar_02a7ef66fce8_128.png" backup-post-limit="30000"/>
</tumblr>
and get the avatar-url field of the corresponding tumblelog. Too bad there is no json format option, maybe use preg_match. You also need the email address and password of the user, or do it via OAuth.
Or you could scrape the tumblelog for the avatar.
$page = file_get_contents("http://{$tumblog}.tumblr.com/");
$avatar = preg_match('/<img src="(http.+)" alt="portrait"/', $page, $matches) ? $matches[1]: 'http://example.com/blank.png';

Related

OG Tags via php

I'm trying to make a very simple game.
a) I let the user input his name;
b) I put this name in a canvas;
c) I generate an image (base64) whit canvas.toDataRL() and I create an image file sending the base64 URI to a php file. I'm doing it with this code:
JAVASCRIPT:
var canvas = document.getElementById("myCanvas");
var dataURL = canvas.toDataURL("image/jpeg", 0.2);
//console.log(dataURL);
// post the dataUrl to php
$.ajax({
type: "POST",
url: "upload.php",
data: {image: dataURL}
}).done(function( respond ) {
console.log(respond);
});
UPLOAD.PHP
<?php
if ( isset($_POST["image"]) && !empty($_POST["image"]) ) {
$dataURL = $_POST["image"];
$parts = explode(',', $dataURL);
$data = $parts[1];
$data = base64_decode($data);
// create a temporary unique file name
$file = "img/" . UPLOAD_DIR . uniqid() . '.png';
// write the file to the upload directory
$success = file_put_contents($file, $data);
print $success ? $file : 'Unable to save this image.';
}
?>
d) Now I'd like to use this image that I've created to set the og:image tag (to share it on Facebook)! How can I do? I've honestly no idea.
Thank you!
Maybe in the OG you can put the link with <?php echo $file; ?>
I've found out the solution.
I pass the respond via get to another php page that catch the get parameter and put it in the og:image'content part.
You can debug your OG markup here: https://developers.facebook.com/tools/debug/
General information about open graph markup: https://developers.facebook.com/docs/sharing/webmasters#markup

Adding an additional field to login with AWD Facebook Wordpress Plugin

I am using AWD Facebook wordpress plugin to allow my visitors to login with their Facebook account information. When a visitor registers on my site I automatically create a new post that is titled with their username and includes their Facebook profile picture as the content. The code for that is below:
function my_create_page($user_id){
$fbuide = 0;
$the_user = get_userdata($user_id);
$new_user_name = $the_user->user_login;
$new_user_avatar = get_avatar($the_user->user_email);
global $AWD_facebook;
$fbuide = $AWD_facebook->uid;
$headers = get_headers('http://graph.facebook.com/' . $fbuide . '/picture?type=large',1);
if(isset($headers['Location'])) {
$url = $headers['Location']; // string
} else {
$url = false;
}
$my_avatar = "<img src='" . $url . "' class='avatar AWD_fbavatar' alt='" . $alt . "' height='" . $size . "' />";
$my_post = array();
$my_post['post_title'] = $new_user_name;
$my_post['post_type'] = 'post';
$my_post['post_content'] = $my_avatar;
$my_post['post_status'] = 'publish';
wp_insert_post( $my_post );
}
add_action('user_register', 'my_create_page');
What I am looking to accomplish is a bit different though. I also want to include a brief biography about the user (currently the post is simply their picture). So when a visitor logs in with AWD Facebook, their needs to be an additional field that allows the user to type in their bio. Then I would be able to grab that info from their user profile and include it in the post. Any ideas on how I can accomplish this? Is there a different way to do this?
I would recommend storing their Facebook picture as metadata and use the content area as their bio for the automatically generated post. So something like this should get you started:
$my_post = array(
'post_title'=>$new_user_name,
'post_type'=>'post',
'post_content'=>'',
'post_status'=>'publish'
);
if( $id = wp_insert_post( $my_post ) ){
update_post_meta($id, 'avatar', $url);
}
Then you can generate the loop like so:
if ( have_posts() ) : while ( have_posts() ) : the_post();
//... stuff here
$avatar = get_post_meta($post->ID, 'avatar', 'true');
the_content();
echo '<img class="avatar AWD_fbavatar" src="'.$avatar.'" alt="'.$alt.'" height="'.$size.'" />';
endwhile;endif;

posting images into users feed with source is not working

i am trying to create a fb app using the user profile pic. app will generate a new image that image should post to user feed. I am trying to use "source" but it is not working. This is not giving full image. It gives thumbnails instead of posting full image. Here is my code
$canvas = imagecreatetruecolor($crop_width,$crop_height);
imagecopy($canvas,$currentimage,0,0,0,0,$crop_width,$crop_height);
$test = $data['user_id'].'test.jpg';
imagejpeg($canvas, $test,100);
$new = imagecreatetruecolor(150,150);
imagecopyresized($new,$canvas,0,0,0,0,150,150,$w,$crop_height);
$resize1 = $data['user_id'].'resize1.jpg';
imagejpeg($new, $resize1 ,100);
$source1 = 'black.jpg';
$background = imagecreatefromjpeg($source1);
$resize = imagecreatefromjpeg($resize1);
imagecopy($background,$resize,100,250,0,0,150,150);
$output = $data['user_id'].'output.jpg';
imagejpeg($background,$output,100);
echo '<div align="center"><img src="'.$output.'"></div>';
unlink($test);
unlink($resize1);
$access_token = "ABCDEFGHIJKLM";
$graph_url ="https://graph.facebook.com/me/feed?access_token=".$access_token."&method=post&source=http://www.Google.es/images/srpr/nav_logo39.png&message=logo";
$user_permissions = json_decode(file_get_contents($graph_url));
print_r($user_permissions);
Please help me this solves me to create a perfect fb app.

PHP mail function not working

I do not think the problem lies with the mail function code, but with my aproach of the $_SESSION variables. I have a form consisting of 5 pages, the fifth being a preview page. Upon the final submission, on the preview page, i want the entire $_SESSION data to be sent to two different email adresses.
I am displaying the data on the preview page as follows:
<?php
//retrieve session data
echo "<b> Varname: </b>". $_SESSION['varname'];
?>
in a form with method="post" and action="mail.php".
In the mail.php, i start the session, and then:
$_SESSION['email'] = $mail;
$_SESSION['varname'] = $varname;
$email_from = 'mail#company.de';
$email_subject = "Mail";
$email_body = "You have submitted the following data: $inhalt.\n";
$to = "mymail#company.de, $mail";
$headers = "From: Company";
mail($to,$email_subject,$email_body,$headers);
Upon submitting the form the page goes to blank. What exactly am i doing wrong?
I managed to solve the problem in the end, as follows:
$email_from = 'mail#company.de';
$email_subject = "Mail";
$to = ("myadress#work.de," . $_SESSION['email'] . "");
mail($to,"Form submission","Form data:
Inhalt: " . $_SESSION['inhalt1'] . "
");
As I said in the question, the problem was my aproach of the $_SESSION variables. Instead of $_SESSION['varname'] = $varname, i just went directly with . $_SESSION['varname'] .ยด.

upload a image with post method with xml

I am bit stuck about how to pase the image in post method with xml parsing .
I am able to send the string values but dont know how to send the images .
A code snippet will be very helpful or any tutorial or link.
My url is something like this
http://66.45.25.240/XML/EditProfile.aspx?myguid=45&guid=45&name=aditya&email=xyz#gmail.com&cell=1234567890&title=Title&twitterhandle=tutu.com&facebookhandle=ad#ad.com&picture=a124.jpg
Here i dont know how to pass the picture part .
Regards
Mrugen
You shouldn't use HTTP GET because the possible length of the parameters is very limited.
Use POST instead. Here's a link to an example
<?php
$i= 0; // counter
$url = "http://post.jagran.com/rss/post/category/Bollywood.xml"; // url to parse
$rss = simplexml_load_file($url); // XML parser
// RSS items loop
print '<h2><img style="vertical-align: middle;" src="'.$rss->channel->image->url.'" /> '.$rss->channel->title.'</h2>'; // channel title + img with src
foreach($rss->channel->item as $item) {
if ($i < 10) { // parse only 10 items
print ''.$item->title.'<br />';
print ''.$item['image']->url.'<br />';
}
$i++;
}