<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>140dev &#187; API error</title>
	<atom:link href="http://140dev.com/twitter-api-programming-blog/category/api-error/feed/" rel="self" type="application/rss+xml" />
	<link>http://140dev.com</link>
	<description>Twitter API Programming Tips, Tutorials, Source Code Libraries and Consulting</description>
	<lastBuildDate>Wed, 31 Jul 2019 10:03:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.6</generator>
		<item>
		<title>Most common Twitter OAuth programming errors</title>
		<link>http://140dev.com/twitter-api-programming-blog/most-common-twitter-oauth-programming-errors/</link>
		<comments>http://140dev.com/twitter-api-programming-blog/most-common-twitter-oauth-programming-errors/#comments</comments>
		<pubDate>Sat, 26 Jan 2013 14:31:19 +0000</pubDate>
		<dc:creator>Adam Green</dc:creator>
				<category><![CDATA[API error]]></category>
		<category><![CDATA[Twitter API Tutorials]]></category>
		<category><![CDATA[Twitter OAuth]]></category>

		<guid isPermaLink="false">http://140dev.com/?p=1992</guid>
		<description><![CDATA[My Twitter OAuth ebook has been out for 2 weeks now, and I&#8217;ve had a chance to help a lot of people get over the hump of running their first OAuth code. I&#8217;ve collected a list of the most common problems they have: No callback URL When you create an app, Twitter has an input [&#8230;]]]></description>
				<content:encoded><![CDATA[<p></p><p>My <a href="http://140dev.com/twitter-api-programming-blog/twitter-api-ebook-single-user-twitter-oauth-programming/">Twitter OAuth ebook</a> has been out for 2 weeks now, and I&#8217;ve had a chance to help a lot of people get over the hump of running their first OAuth code. I&#8217;ve collected a list of the most common problems they have:</p>
<p><strong>No callback URL</strong><br />
When you create an app, Twitter has an input field on the application creation page for filling in a callback URL. The URL is used when you create an OAuth login interface that lets people sign in on your site with Twitter. So if you are doing single-user OAuth, you could reasonably think that you can leave this blank. Twitter encourages this thinking by not requiring you to fill in the field on this form. The notes under the field also imply that you don&#8217;t need it: &#8220;To restrict your application from using callbacks, leave this field blank.&#8221; I&#8217;m not sure what this note means, but I do know that you MUST include a callback URL. If you don&#8217;t, the tmhOAuth library will not be able to make an OAuth connection and none of your API code will work. What URL should you use? It doesn&#8217;t matter, as long as it is valid. You can even use http://twitter.com. </p>
<p><strong>Failure to set read write access</strong><br />
The Settings tab in the app creation page has a set of radio buttons that let you set the access level to read write. For some reason, this option is not displayed when you first create an app. You have to create the app, which is set to read only access by default, and then go to the Settings tab and change the access to read write. If you leave it as read only, you will not be able to tweet, follow, or do anything else with the API that changes an account. </p>
<p><strong>Incorrect server clock</strong><br />
The OAuth system is very sensitive to differences between Twitter server clocks and your server. If your server&#8217;s clock is off by more than 5 or 10 minutes, all your OAuth requests will fail. If you don&#8217;t know how to check or set your server clock, ask your webhost. </p>
<p><strong>Duplicate tweet</strong><br />
Some people have tried running my example post_tweet.php script and got a 403 error. This generally means that you have sent a duplicate tweet. There is a time limit after which duplicate tweets are allowed, but I&#8217;ve never been able to get an answer from Twitter HQ on what it is. If you get a 403 error when posting a tweet with the API, check your timeline to make sure this is not a duplicate of what you have already sent recently. </p>
<p><strong>tmhOAuth files not found</strong><br />
There are only 2 files from the tmhOAuth files that you must use: cacert.pem and tmhOAuth.php. They both MUST be in the same directory and you have to use a valid path when you require or include tmhOAuth.php. </p>
<p><strong>Invalid tmhOAuth files</strong><br />
I include the latest copies of the tmhOAuth files in the zip for the ebook, but some people prefer to download them from their home site at <a href="https://github.com/themattharris/tmhOAuth">https://github.com/themattharris/tmhOAuth</a>. That is fine, but you have to make sure you download clean copies of these files. I worked with someone for quite a while until we figured out that he had downloaded the entire page from Github, including the HTML, when he downloaded them. </p>
<p>I&#8217;m still interested in hearing about any problems you have with the ebook code. I want to make sure this is as clean as possible. <a href="mailto:140dev@gmail.com">Email me</a> if you can&#8217;t get it to work. </p>
]]></content:encoded>
			<wfw:commentRss>http://140dev.com/twitter-api-programming-blog/most-common-twitter-oauth-programming-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dealing with 500 errors when retrieving user data</title>
		<link>http://140dev.com/twitter-api-programming-blog/dealing-with-500-errors-when-retrieving-user-data/</link>
		<comments>http://140dev.com/twitter-api-programming-blog/dealing-with-500-errors-when-retrieving-user-data/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 15:32:43 +0000</pubDate>
		<dc:creator>Adam Green</dc:creator>
				<category><![CDATA[API error]]></category>
		<category><![CDATA[Database Cache]]></category>

		<guid isPermaLink="false">http://140dev.com/?p=1237</guid>
		<description><![CDATA[I got a call the other day from a developer who was receiving various 500 series errors when trying to gather large amounts of Twitter user data. The API has a number of errors in the 500 range, all of which generally mean that the Twitter servers are overloaded. The API is built on the [&#8230;]]]></description>
				<content:encoded><![CDATA[<p></p><p>I got a call the other day from a developer who was receiving various 500 series errors when trying to gather large amounts of Twitter user data. The API has a number of errors in the 500 range, all of which generally mean that the Twitter servers are overloaded. The API is built on the principle of staying alive while handling as many requests as possible. If the load gets too high or a request takes too long to process, the request is dumped and one of the 500 errors is returned.</p>
<p>The specific requirement for this developer was getting information on all the followers of his app&#8217;s users. He was doing this in a brute force fashion every 24 hours. First looking up all the followers 5,000 at a time with the <a href="https://dev.twitter.com/docs/api/1/get/followers/ids">/followers/ids</a> call. Then getting the profile data for each of these followers 100 at a time with <a href="https://dev.twitter.com/docs/api/1/get/users/lookup">/users/lookup</a>. This is a very intensive use of the API, and it is exactly what Twitter doesn&#8217;t want you to do. Look at the hint they are offering by returning 5,000 follower ids in a single call, but doling out profile data on only 100 users. They are telling us not to request too much user data.</p>
<p>Whenever possible you should be caching data you get from the API. User profiles are a perfect example. Instead of requesting data on every user every 24 hours, it is much better to store user profiles in a database, and request this data less often. Cutting back to once every 7 days reduces the number of API calls by 86%. I recommended that he adopt this type of caching and then check the user ids he receives from /followers/ids against the user database table. If the user is new or hasn&#8217;t been updated recently, then request the profile with /users/lookup. </p>
<p>It also helps to be opportunistic about caching. Many of the API calls return a user&#8217;s profile in the payload. If you get this data anywhere in your code, take advantage of this opportunity to cache it. </p>
<p>The other solution to 500 errors is to request less data each time. As I said, a 500 error is often a time out. While the /users/lookup call allows you to request 100 users at a time, try backing off to just 50 at a time. It will take more API calls, but you&#8217;ll have a better chance of getting results without an error. This type of logic should be built into your code. If a request triggers a 500 error, scale back the quantity requested and repeat the call. </p>
]]></content:encoded>
			<wfw:commentRss>http://140dev.com/twitter-api-programming-blog/dealing-with-500-errors-when-retrieving-user-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
