Tech titans Facebook and Apple have a contentious relationship that is frequently put to the test. But a Facebook for TouchPad application was very nearly the last straw, Mashable has learned from multiple sources.

Facebook and Apple, united by a common interest in beating Google, will finally put their differences aside to launch the long-overdue Facebook for iPad app Tuesday.

We also expect announcements on a new Facebook for iPhone application, a Facebook HTML5 mobile app platform, and perhaps even Facebook integration in iOS 5.

This all marks a significant leap forward in the sometimes hostile Facebook and Apple relationship. It began well when Apple first set up an Apple Students group on Facebook in 2006 — "a monster success" for both companies, according to a source who spoke with Mashable on the condition of anonymity.

But the companies would butt heads many times in the following years.

How Ping Went Wrong

The most publicized confrontation involved Ping, Apple's attempt at an iTunes social network. Ping first launched with Facebook integration in September 2010, but Facebook quickly pulled Apple's access to its APIs. This alerted the media to a growing rift between the companies.

A source familiar with the chain of the events attributes the Ping debacle to a disagreement over iOS 4. Apple had fully integrated Facebook into the iPhone and iPad's operating system, and was ready to launch the mobile-social fusion when API negotiations broke down. Apple, lacking confidence in Facebook's ability to build a great application, asked to build its own Facebook for iPhone app. Facebook responded with a firm no. Negotiations came to halt.

Meanwhile, Apple was working away on Ping — and due to the stalled iOS 4 talks, decided to keep Facebook mostly out of the loop. Facebook, surprised by Ping's launch, turned off Apple's access to its APIs. The rest was history.

Jobs vs. Zuck

Facebook for iPad Leak

Roughly three months ago, Steve Jobs — then the Apple CEO — paid a visit to Facebook to discuss a Facebook for iPad application with CEO Mark Zuckerberg.

Zuckerberg promised Jobs that the social network would release its first ever tablet application for iPad. Jobs, however, learned during his visit that HP was about to release a native webOS Facebook application for the TouchPad.

Indeed, back on February 9, 2011 — the date HP revealed its almost defunct TouchPad tablet — HP SVP of Applications and Services Steven McArthur did tout the fact that the company had been working closely with Facebook.

The Facebook application that HP finally launched in July, however, appears to be an unofficial build that disappointed users.

So what happened to the rich Facebook for TouchPad application that HP promised?

HP Plays the Cuckold

<a href="http://www.pcmag.com/article2/0,2817,2387970,00.asp"><img src="http://mashable.com/wp-content/uploads/2011/09/fb-for-touchpad.jpg" alt="" title="fb for touchpad" width="375" height="500" class="size-full wp-image-751843" /></a>





When Jobs learned of the webOS Facebook app during his summer visit to Facebook, he was livid. Zuckerberg vowed to get the app pulled. But Jon Rubinstein, the former CEO of Palm and then the GM of HP's webOS division, refused to halt the release of the app. Facebook responded by restricting HP's access to its APIs — just as it had done with Apple's Ping, a year earlier.

Was Facebook playing both sides? Absolutely, says a source close to HP. Facebook was made aware of the application and device integrations. The company knew what was coming, changed its tune right before release — and only did so to appease Apple.

For its part, HP was furious. It had hoped the Facebook application would help differentiate the TouchPad from other tablets on the market. Another source says that HP may have considered legal action. In any case, the TouchPad was discontinued shortly after.

Kiss and Make Up?

So Facebook and HP may be on the outs, but Facebook and Apple appear to have patched up their differences.

Not only are the pair finally aligned on the Facebook for iPad application, but they've been working together closely on Facebook's HTML 5 mobile app platform.

This is the closest Apple and Facebook have been to creating something meaningful together, one source says. They're partnering because they share a common enemy: Google.

Still, there are no guarantees. Both companies are said to be scrambling to work out the final details prior to the iPhone 5 launch event on Oct. 4.

We've reached out to Apple, Facebook and HP for on-the-record comment.

Mashable's Editor at Large Ben Parr and Entertainment Editor Christina Warren contributed to the reporting of this story.