Archive for web 2.0

Instagram curl -F to request an access_token

I have been working with the Instagram API for my client project, So below is the code snippet to get userid (if user logged with instagram).
I got the reference code from here (http://instagram.com/developer/authentication/) and the below one is i have tried with the php language.

Info about Curl -F -> curl is a linux utility that simulates web requests. Issuing a curl -F command issues a http request with form submission data.

$curl_attr = array(“client_id”=>$instagram_client_id, “client_secret”=>$instagram_client_secret, “grant_type”=>”authorization_code”, “redirect_uri”=>”Your Redirect URI”,”code”=>$insta_access_code);

$curl_output = curl_download(‘https://api.instagram.com/oauth/access_token’,$curl_attr);

function curl_download($Url,$fields){
$fields_string = “”;
if (!function_exists(‘curl_init’)){
die(‘Sorry cURL is not installed!’);
}
foreach($fields as $key=>$value) { $fields_string .= $key.’=’.$value.’&’; }
rtrim($fields_string, ‘&’);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}

I will update this post with full api soon.

Customizing the Read More link with WordPress

If you have set your WordPress site to display post excerpts on the front or home page, you will want visitors to click on the title or a link to encourage them to continue reading your post or article, right? WordPress makes this technique easy, and customizable.

Here is the steps:

  • Go to wordpress admin panel –> Design tab –> Theme Editor.
  • Select Main Index template (index.php) to edit it
  • Find the line  “<?php the_content(‘Read the rest of this entry &raquo;’); ?>”
  • And replace it with the following code.

<?php

$content = get_the_content($more_link_text, $stripteaser, $more_file);
if(strlen($content)>500) // chanage 500 as per your needs
{
$part_msg=substr($content, 0, 500);// chanage 500 as per your needs
echo ‘<p>’.$part_msg.’… ‘;
?>
<br /><br />
<a href=”<? comments_link(); ?>”>Read More…</a></div>
<?php
echo ‘</p>’;
}
else
{
echo ‘<p>’.$content.’</p></div>’;
}

?>

Where “500″ represents number of characters that you want to show.

If you cannot able to make the above changes with the wordpress theme editor, use your ftp.

Here is the template directory

/public_html/blog/wp-content/themes

or

/www/blog/wp-content/themes

where blog is the directory where i installed my wordpress

Part of Page refresh using AJAX with timed delay

<head>
<script type=”text/javascript”>
function makAx() // this function to activate XMLHttpRequest Object
{
try
{
xm = new ActiveXObject(“Msxml2.XMLHTTP”);
return true;
}
catch (e)
{
try
{
xm = new ActiveXObject(“Microsoft.XMLHTTP”);
return true;
}
catch (e2)
{
xm = false;
}
}
if (!xm && typeof XMLHttpRequest != ‘undefined’)
{
xm = new XMLHttpRequest();
return true;
}
}
function showImages()
{
if(makAx()) // XMLHttpRequest checked here
{
url = “external-page-for-db-query.php”; // this file will contains your db query
callavail();
}
}
function callavail()
{
xm.open(“GET”,url,true); // This is ajax functionality. It may have true(for synchronous request) or false(for asynchronous request)
xm.onreadystatechange = cavail;
xm.send(null);
}
function cavail()
{
if(xm.readyState == 4) // If ready state reached
{
var response = xm.responseText;
var str = document.getElementById(“showResult”); // result of “external-page-for-db-query.php” will come here
str.innerHTML = response;
setTimeout(“showImages()”,1000); // here 1000 represents one second for time delay. showImage() function will be called with the specified time delay
}
}
</script>
</head>

<body>
<div id=”showResult”></div> <!–page result will be displayed here–>
</body>
</html>