twitter rest api - post a status with a user mention

倾然丶 夕夏残阳落幕 提交于 2021-02-19 08:55:05

问题


Using twitter's rest api, and specifcally the method :

https://dev.twitter.com/docs/api/1/post/statuses/update

I'm trying to post a tweet that will include a user mention ( @[screenname] ). However, it seems as though twitter won't allow me to post any @ sign unless I encode it. I've tried several encoding techniques, but non seem to provide me with the suitable encoding twitter is looking for.

As to the question, What should "@" be substitute with so twitter will allow me to pass the message correctly? I'm posting the command via an iphone app, and from several reasons I cannot use either ios 6 new social integration, nor twitter's api wrapper for ios.

Edit: The encoding techniques I've tried -

  • stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding
  • How do I URL encode a string

Thank you


回答1:


As it seems I had to specifically percent encode the @ using the following method:

bodyString = [bodyString stringByReplacingOccurrencesOfString:@"@" withString:@"%40"];

Hope it will help someone in the future.



来源:https://stackoverflow.com/questions/16020649/twitter-rest-api-post-a-status-with-a-user-mention

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!