Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Generate tiny url with PHP
Old 12-28-2010, 02:37 PM Generate tiny url with PHP
Junior Talker

Posts: 1
Trades: 0
I have a client with a Wordpress blog. They are posting pictures to Twitter after emailing to blog as a post manually. The process

1. Email picture to Wordpress
2. Post is created
3. Manually shorten url using bit.ly
4. Post to twitter.

I would like to automate it. The plug currently generates a short url using the domain, bit.ly would be shorter. Here is the plug in code:

Code:
// Generate URL
    $url = preg_replace('/\/$/', '', (get_option('twitter_image_host_override_url_prefix') ? get_option('twitter_image_host_override_url_prefix') : get_option('siteurl'))).'/'.$tag;

Here is the code I found to generate the short url. Having trouble combining the two. 

function shortUrl ($url)
{
  $bitlyUser = 'TEST';
  $apiKey = 'API_KEY';

  $ch = curl_init();

  //cURL options
  curl_setopt($ch, CURLOPT_URL, 'http://api.j.mp/v3/shorten?login=' . $bitlyUser . '&apiKey=' . $apiKey .'&uri=' . htmlspecialchars($url) . '&format=txt');
  curl_setopt($ch, CURLOPT_HEADER, false);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  //Execution
  $ret = curl_exec($ch);
  curl_close($ch);
  return $ret;
Any ideas? Appreciate it. Thanks!

Billy

Last edited by chrishirst; 03-04-2011 at 03:56 PM..
bstrawjr is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-24-2011, 12:07 PM Re: Generate tiny url with PHP
RonnieTheDodger's Avatar
Extreme Talker

Posts: 232
Location: Central USA
Trades: 0
I would either install, or disect, the plugin called WP-to-Twitter.

This plugin handles multiple Url shortening services and auto-tweets new posts. You can also customize the format of the tweets, auto hashtags, etc.
__________________
Ronnie T. Dodger

[
Please login or register to view this content. Registration is FREE
] [
Please login or register to view this content. Registration is FREE
]
RonnieTheDodger is offline
Reply With Quote
View Public Profile Visit RonnieTheDodger's homepage!
 
Old 03-02-2011, 11:05 PM Re: Generate tiny url with PHP
vivekar's Avatar
Webmaster Talker

Posts: 612
Trades: 0
I do not see any issues in the code.

You can also try goo.gl which is faster. It also has an API.
__________________

Please login or register to view this content. Registration is FREE
(Active since 2003) |
Please login or register to view this content. Registration is FREE
vivekar is offline
Reply With Quote
View Public Profile Visit vivekar's homepage!
 
Reply     « Reply to Generate tiny url with PHP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17268 seconds with 12 queries