To check if a tweet contains a link to an external site, I'm just checking that the tweet contains 'http:' ? Will this suffice ?
I'm accessing the tweets using the twitter rest API, so I parse the json response which contains the tweets.
You can get all the URLs of a tweet using Twitter Entities. When you make the REST call, make sure you include
&include_entities=true
This will give you a section in the JSON or XML called entities. There will be a child node called urls.
Here's an example of what will be returned.
"text": "Twitter for Mac is now easier and faster, and you can open multiple windows at once http://t.co/0JG5Mcq",
"entities": {
"media": [
],
"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
]
}
],
"user_mentions": [
],
"hashtags": [
]
}
So, look for entities -> urls to see if a tweet contains a link to an external site.
How do you access the tweets? By scraping the twitter site, or through some API? If you use an API, which one, etc. It looks to me like the js-tweet-text section of the source is always formatted to give a link with http://, but it might not be guaranteed. Why don't you just look for href instead?
Example:
<p class="js-tweet-text">
Blabla tweet text... <a data-expanded-url="http://bit.ly/somelink"
class="twitter-timeline-link" href="http://t.co/stuff"
rel="nofollow" class="twitter-timeline-link">bit.ly/somelink
</a>
</p>
Here, both data-expanded-url and twitter-timeline-link seem to give the actual link, while href redirects you via some twitter filter. But anyway, one thing you can be certain of is that links contain a href.
Related
Unless I'm missing something, In the Twitters Docs it only shows you how to use and fetch JSON from a single Twitter Moment. Can you fetch an array / list of all trending Twitter Moments?
It shows in their example in their docs
GET https://publish.twitter.com/oembed?url=https://twitter.com/i/moments/650667182356082688
would return
{
"url": "https://twitter.com/i/moments/650667182356082688",
"title": "The Obamas' wedding anniversary",
"html": "<a class=\"twitter-moment\" href=\"https://twitter.com/i/moments/650667182356082688\">The Obamas' wedding anniversary</a>\n<script async src=\"//platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>",
"width": 550,
"height": null,
"type": "rich"
"cache_age": "3153600000",
"provider_name": "Twitter",
"provider_url": "https://twitter.com",
"version": "1.0"
}
I'd prefer a non-embedded version of this but can work with it if I only get a url to the embedded version
There's no API for working with Moments right now (and it is not currently on the API roadmap). The only function that is exposed is the oEmbed capability to embed Moments on other sites, and that does indeed require you have have the URL to the relevant Moment from the website (or from the share link in the app).
I have created a web application from which I am trying to get recommendations of a user from his/her LinkedIn Profile using URL
String url="https://api.linkedin.com/v1/people/~:(recommendations-received:(id,recommendation-type,recommendation-text,recommender))?format=json"
When I am using this URL in the
Api Explorer it works fine. And gives output:-
{ "recommendationsReceived": {
"_total": 2,
"values": [
{
"id": 558598601,
"recommendationText": "xxx is among the best team players I ever worked with. He has handled client effectively with smooth operations. I had always seen him as person with solution mindset and always look for solution rather than thinking about the problem. ",
"recommendationType": {
"code": "colleague"
},
"recommender": {
"firstName": "XXX",
"id": "YYYY",
"lastName": "XXX"
}
},
{
"id": ZZZZ,
"recommendationText": "XXX is one of the most dedicated person at work.I always him with a flexible attitude and ready to adapt himself in all situation.I have seen him work all night to catch up all the deadlines and deliver on time ."
"recommendationType": {
"code": "colleague"
},
"recommender": {
"firstName": "XXX",
"id": "YYYY",
"lastName": "XXXX"
}
}
] } }
The problem comes, when I am using this URL in my Developer app.It doesn't give any error just simple return an empty map [:] as output in response
Irrespective of these recommendation fields, I successfully get the user basic profile data such as email, id, image,firstName,lastName.Means my code is working for other fields well but not for these recommendation fields*
To find the solution, I did some internet surfing and find a link of Linked API docs
Linked API Docs
As per Docs following selection of profile fields are only available
to applications that have applied and been approved for the Apply with
LinkedIn program:
Recommendation Fields
I already created a LinkedIn Developer account to get key & Secret
So how do I apply and get approval for Apply with LinkedIn Recommendation Fields.
I already have seen the LinkedIn support but can't find the way to ask question to the Linked Developer help support
Please suggest me the right way.
After a long internet surfing,I have found something fruitful that, I have to fill up a form to get these fields.Here is the form
along with its procedural details
You can use just recommendations-received keyword. Try the following link. I am getting all recommendations details with this link.
https://api.linkedin.com/v1/people/~:(recommendations-received)?format=json
I'm currently working on iOS Application with RestKit 0.20 to access data from Tastypie API.
And I am trying to get feeds data from URL like this
/api/v2/feed/?format=json
Then I will get array of feeds as below.
{
"meta": {
"limit": 20,
"next": null,
"offset": 0,
"previous": null,
"total_count": 2
},
"objects": [
{
"id": 1,
"info": "This is my first post",
"pub_date": "2013-02-03T15:59:33.311000",
"user": "/api/v2/user/1/",
"resource_uri": "/api/v2/feed/1/"
},
{
"id": 2,
"info": "second post, yeah",
"pub_date": "2013-02-03T16:00:09.350000",
"user": "/api/v2/user/1/",
"resource_uri": "/api/v2/feed/2/"
}
]
}
if I want to fetch more data about user which Tastypie send it as url like a foreign key "user": "/api/v2/user/1/", do I have to nested call objectRequestOperation.
I'm confusing because I'm using block to callback when data is successful loaded. So is there any better way than requesting user data again for each feed after requesting feed complete.
Thank you very much :)
You have to define in the Feed resource :
user = fields.ToOneField(UserResource, full=True)
More info in the tastypie doc http://django-tastypie.readthedocs.org/en/latest/resources.html
Why Resource URIs?
Resource URIs play a heavy role in how Tastypie delivers data. This can seem very different from other solutions which simply inline related data. Though Tastypie can inline data like that (using full=True on the field with the relation), the default is to provide URIs.
URIs are useful because it results in smaller payloads, letting you fetch only the data that is important to you. You can imagine an instance where an object has thousands of related items that you may not be interested in.
URIs are also very cache-able, because the data at each endpoint is less likely to frequently change.
And URIs encourage proper use of each endpoint to display the data that endpoint covers.
Ideology aside, you should use whatever suits you. If you prefer fewer requests & fewer endpoints, use of full=True is available, but be aware of the consequences of each approach.
Just noticed a spike of visitors following a t.co/LINKHERE a link re-written by twitter. Is there a way to track back to the twitter message that contained the link, if you know the link?
You can do this using twitter API 1.1. The easiest way is to use the api is through the twitter API console. Here are the steps:
Goto https://dev.twitter.com/rest/tools/console
Select https://api.twitter.com/1.1 from the Service dropdown menu.
Select OAuth 1 from the Authentication dropdown menu and authorize with your twitter account.
Choose GET /search/tweets.json api.
Type the t.co link (e.g. https://t.co/w6iqrcuZMA) in q query parameter (Try both http and https links. In my case the http link returned no record while https link returned some records). All the search results will be returned in json format.
Now to open the actual tweet use this link (fill the placeholders of course): https://twitter.com/{user.screen_name}/status/{id_str}
The standard twitter search will work for a few days.
For older t.co links, you could try searching with
find-tco.appspot.com.
Here’s the quick and easy way:
Go to: http://dev.twitter.com/rest/tools/console
Service: “api.twitter.com/1.1”
Authentication: OAuth 1, then log in if you need to
Make sure GET is selected and paste https://api.twitter.com/1.1/search/tweets.json?q=http%3A%2F%2Ft.co%2F{**SUFFIX**} into the Request URL box.
Replace **SUFFIX** with the t.co URL suffix. So if the URL you’re searching for is t.co/**N2ul8FFCxu**, the link you pasted should look like this:
https://api.twitter.com/1.1/search/tweets.json?q=http%3A%2F%2Ft.co%2F{**N2ul8FFCxu**}
Click Send
Open a new tab and paste twitter.com/**SCREEN_NAME**/status/**ID_STR** into the address bar
Replace **SCREEN_NAME** and **ID_STR** with info from Response. Like this:
twitter.com/**twitter**/status/**526534593826938881**
t.co links do show up in search, so if you're curious, you have about a week to find them before they get dropped from the search index.
For example:
http://search.twitter.com/search.json?q=https:%2F%2Ft.co%2FGJMsIcM6
Returns:
{
"completed_in": 0.019,
"max_id": 178215431251828740,
"max_id_str": "178215431251828736",
"page": 1,
"query": "https%3A%2F%2Ft.co%2FGJMsIcM6",
"refresh_url": "?since_id=178215431251828736&q=https%3A%2F%2Ft.co%2FGJMsIcM6",
"results": [
{
"created_at": "Fri, 09 Mar 2012 20:27:24 +0000",
"from_user": "kurrik",
"from_user_id": 7588892,
"from_user_id_str": "7588892",
"from_user_name": "Arne Roomann-Kurrik",
"geo": null,
"id": 178215431251828740,
"id_str": "178215431251828736",
"iso_language_code": "en",
"metadata": {
"result_type": "recent"
},
"profile_image_url": "http://a0.twimg.com/profile_images/24229162/arne001_normal.jpg",
"profile_image_url_https": "https://si0.twimg.com/profile_images/24229162/arne001_normal.jpg",
"source": "<a href="http://twitter.com/tweetbutton" rel="nofollow">Tweet Button</a>",
"text": "RT #raffi: “Twitter Catches the 'SPDY' Train” from #wired → http://t.co/suCbWWEl (& they reference my tweet! → https://t.co/GJMsIcM6)",
"to_user": null,
"to_user_id": null,
"to_user_id_str": null,
"to_user_name": null
},
{
"created_at": "Fri, 09 Mar 2012 20:26:26 +0000",
"from_user": "raffi",
"from_user_id": 8285392,
"from_user_id_str": "8285392",
"from_user_name": "Raffi Krikorian",
"geo": null,
"id": 178215186921033730,
"id_str": "178215186921033730",
"iso_language_code": "en",
"metadata": {
"result_type": "recent"
},
"profile_image_url": "http://a0.twimg.com/profile_images/1270234259/raffi-headshot-casual_normal.png",
"profile_image_url_https": "https://si0.twimg.com/profile_images/1270234259/raffi-headshot-casual_normal.png",
"source": "<a href="http://twitter.com/tweetbutton" rel="nofollow">Tweet Button</a>",
"text": "“Twitter Catches the 'SPDY' Train” from #wired → http://t.co/suCbWWEl (& they reference my tweet! → https://t.co/GJMsIcM6)",
"to_user": null,
"to_user_id": null,
"to_user_id_str": null,
"to_user_name": null
}
],
"results_per_page": 15,
"since_id": 0,
"since_id_str": "0"
}
You'll see that search returns retweets as well.
I'm using the Google Contacts API to get back formatted JSON, hopefully containing ALL of a user's contacts' email addresses. I use this information to search my database for the user's friends.
Neither of these results occur.
Here's the URI that's called (broken up by paramater for slightly better readability:
http://www-opensocial.googleusercontent.com/api/people/#me/#all/?
filterby=emails&max_results=1000
&oauth_consumer_key=XXXXXXX
&oauth_nonce=h7ZEI
&oauth_signature=6U2ywoPRFu8iJdQhjMRk%2FZlf%2FBg%3D
&oauth_signature_method=HMAC-SHA1
&oauth_timestamp=1283979209
&oauth_token=1%2Fwv9OYV4LuffVLv6OqlFJLOtTlBo5sYYQkHbZznlLrNk
&oauth_version=1.0
&orderby=starttime
Here's some truncated and anonymized JSON I have returned.
{
"startIndex": 0,
"totalResults": 615,
"entry": [
{
"id": "XXXXXXXXXXXXXXXXXXX",
"name": {
"formatted": "XXXXX XXXXXX",
"familyName": "XXXXXXX",
"givenName": "XXXXXX"
},
"displayName": "XXXXX XXXXXX"
},
],
"itemsPerPage": 20
}
Any thoughts on what's going wrong here would be great.
Hate to answer my own question so soon, but I was using the wrong initial scope. I was using Google's Open Social feed rather than the Google Contacts feed.