Using t.co in sharekit - iphone application

2019-09-01 05:00发布

I am using sharekit but I don't want to use the bityl service for shortening the URL I want to use the built-in t.co provided by twitter.

How can I do that?

Thanks.

1条回答
看我几分像从前
2楼-- · 2019-09-01 05:48

Unfortunately, T.co is not available as an API to developers. It's an internal shortner used by Twitter to automatically shorten long links.

Check out this post by Raffi, Twitter developer, to learn more about it.

You won't be able to control how the links get shortened. But all URL's over 20 characters are automatically shortened and you can control what get's shortened by including wrap_links=true on the POST you send to Twitter for new messages.

If you enable entities in the response you'll see the following attributes for your links.

"urls": [
        {
          "url": "http://t.co/0JG5Mcq",
          "display_url": "blog.twitter.com/2011/05/twitte…",
          "expanded_url": "http://blog.twitter.com/2011/05/twitter-for-mac-update.html",
          "indices": [
            84,
            103
          ]
        }
      ],

For further reference :

Twitter's t.co URL wrapper is now on for all URLs 19 characters and greater

Next steps with the t.co link wrapper


Edit --->

How to get this working with ShareKit:

Twitter does not release an API like bit.ly does for URL's but if you look through the ShareKit library you will see the following file,

/ShareKit/master/Classes/ShareKit/Sharers/Services/Twitter/SHKTwitter.m

open this file and look for the following line:

http://api.bit.ly/v3/shorten?login=%@&apikey=%@&longUrl=%@&format=txt

inside the block

self.request = [[[SHKRequest alloc] initWithURL:[NSURL URLWithString:[NSMutableString stringWithFormat:@"http://api.bit.ly/v3/shorten?login=%@&apikey=%@&longUrl=%@&format=txt",
                                                                          SHKBitLyLogin,
                                                                          SHKBitLyKey,                                                                        
                                                                          SHKEncodeURL(item.URL)
                                                                          ]]

This is the short URL string ShareKit sends to the Twitter sharer.

I haven't had a chance to test this out, but I think if you change this text string to a long URL text string then ShareKit will instead send that one.

Although there may be areas elsewhere in the framework that rely on the Bit.Ly service so watch out for that. But it's worth testing out.

Even though Twitter does not offer a T.co API, as of Aug 15 it has started translating all links to t.co. So, if you use a long URL with the steps mentioned above then you should be seeing T.co in the response.

查看更多
登录 后发表回答