Promoted Tweets是Twitter的一个广告平台。本文作者是发现在Twitter官方的应用中并没有显示一些广告,而决定分析Twitter是不是做了什么手脚。没有详细的步骤,只是可以了解一些工具的使用和Twitter的一个小动作。
Mac上的Twitter有些奇怪的行为: Timeline上的一些内容被过滤掉了. 下图就是一个对比,相较网页版本,其中"howaboutwe.com" 的内容没有在应用程序中显示出来。
这是一个Bug,还是Twitter自己打破了规则? 为什么官方的应用与Web Client得到了不同的数据?
Twitter是不是使用了一些自己未公开的API? 为了找到答案,我对Twitter动了手术刀。
Reverse Engineering Twitter.app
幸运的是这个应用是纯粹使用Objective C编写的, 就可以使用class-dump了解Twitter.app的基本内容以及如何设计的。首先,就发现其中有一个TwitterStatus可能和之前的过滤行为有关。注意其中一个是否promoted的标志位 (命名的重要性):
@interface TwitterStatus : NSObject <...>
{
NSDate *lastUpdated;
...
struct {
...
unsigned int isPromoted:1;
我们就可以假定Twitter就是从API服务器端收到promoted tweets内容,并使用这个标志位加以区分的。
分析数据流(On to the Data Stream)
通过
Hopper.app, 一两小时后,就找到了响应网络数据的代码. 名字是[ABHTTPRequest connection:DidReceiveResponse:]。
在使用GDB (Hopper提供了一个GDB Server可以和Hopper共同使用进行调试)在Twitter.app中设定断点,然后可以看到从服务器拿到什么数据。
在Terminal运行GDB:
> cd /Applications/Twitter.app/Contents/MacOS/
> gdb --arch=i386
然加加载Twitter并设定断点:
> (gdb) exec-file Twitter
> (gdb) b *0x6dec3
> (gdb) commands
> x/s $eax
> end
> (gdb) set print elements 0
> (gdb) r
首选你必须知道Twitter是使用XML传递数据的. API Server先是回应你的用户信息,然后发送你的Timeline feed内容。和网络版本比对,发现其中的内容确实不同。
Is This an Undocumented API?
到底是Twitter.app没有去收那些数据?还是API Server没有返回那些数据呢?
使用Rested for Mac, 可以快速的拉回我的Timeline中的内容。在下面的结果里可以看到API并没有回什么promoted tweets.

结论: Twitter有私有API (Conclusion: Twitter Has A Secret Feed For Promoted Tweets)
Twitter的开发页面中的FAQ显示, "从March 12, 2012起,第三方应用程序将不再有Twitter promoted products相关服务的API (there is no Advertising API for serving Twitter's promoted products in third party applications)." 也就是promoted tweets应当出现在所有使用API的应用中。很明显,事实并非如此。
Michael Schonfeld is head of developer relations at Dwolla, a service that empowers anyone with an Internet connection to send money simply. Follow Michael
Schonfeld and his brotherDaniel Schonfeld on Twitter.
原文地址:http://www.fastcompany.com/3002016/reverse-engineering-twitter-solve-advertising-mystery
转载请注明出处:http://blog.csdn.net/horkychen