问题
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