Using Zend_Service_Twitter to fetch last tweets from a user without using OAuth? - zend-framework

As far as I know Twitter API is supposed to be available with smaller limit rate without API key and without being connected through OAuth.
Is there anyway to use that simply through Zend_Service_Twitter ? Or will I end parsing some kind of feed like that : https://twitter.com/statuses/user_timeline/12345.json?callback=twitterCallback2&count=1

Other question same answer :
$twitter_search = new Zend_Service_Twitter_Search('json');
$response = $twitter_search->search('from:twitter_handle');
print_r($response);die;

Related

How to get live video id from YouTube channel

YouTube API eventType=live not working, does anyone have an idea why?
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCmyKnNRH0wH-r8I-ceP-dsg&eventType=live&type=video&key=
Without eventType was working fine (but not now):
https://www.youtube.com/embed/live_stream?channel=UCmyKnNRH0wH-r8I-ceP-dsg&autoplay=1
Looks like YouTube changed something in API, search.list really not returning live broadcast since end of last week.
If you have user's access token you can use https://www.googleapis.com/youtube/v3/liveBroadcasts?part=snippet&broadcastStatus=active&broadcastType=all
endpoint to retrieve if any broadcast is live.
If you do not have user's access token, you can try this answer
but i didn't check it if it is working
Anyway this question looks like to be a duplicate of this question
Right now the YouTube API is not working, specifically for retrieving live streams of a specific channelId. In other words if you are setting channelId in the API call, you will get 0 results.
If you're using an API key rather than OAuth (not sure if OAuth works) the only work around at the moment is to use the API to search for a specific title. Here is my query URL below.
https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&type=video&maxResults=20&order=date&q=My+Uniquely+Titled+Livestream&key=[apiKey]
The results returned by the API will be from all of YouTube. (Note: the rest is done serverside) Put the results into an array and discard any that don't match your channelId. Then check the titles in an array and only get the video ID of the one that matches your desired title. That is the basic logic and it is sort of a rigid work around that won't work for most. But at least it will get you what you need until Google fixes the API.

Retriving data from facebook events

I have to create an webpage where i need to show all the events from the past or upcoming ones from an facebook page. I have to retrive the title, description, image, time and place of every single one and make a box with it.
After that, i have to retrive all the interested people.
I'm a beginner trying to make big things! Thank you very much.
This isnt a simple problem - I have just done this so will give you a start.
You need to use Facebooks Graph API to get the data, you will need to read up on the Graph API and how to use it. Documentation can be found here. Its worth noting due to a security breach the API isn't offering all of its services to new developers currently but you can get most - read about this here.
You can query the API using any language but I suggest do it with python and use the requests module. Alternatively you could use this SDK which makes things a lot easier, trust me! With the SDK you need to get a user access token which you can get from here.
SDK
With the SDK its possible to do this
import facebook
graph = facebook.GraphAPI(access_token="your_token", version="2.12")
event = graph.get_object(id='event_id',
fields='attending_count,declined_count')
print(event['attending_count'])
print(event['declined_count'])
You can add more fields to the fields list. However you can use any language you choose to request the data, as you can just construct your own URL's.
Graph API & Requests
This is how I did it in python using requests to query the API.
import requests, json
#Make a requests session to fetch data from URL's
session = requests.Session()
session.mount('https://', requests.adapters.HTTPAdapter(max_retries=10))
#API base URL
baseUrl = 'https://graph.facebook.com/v2.11/'
#Fields you want to get
fields = ['id', 'name', 'start_time', 'end_time', 'description', 'place']
#replace CLIENT_ID and CLIENT_SECRET with ones from a facebook app (make one)
tokenPath= 'oauth/access_token?client_id={0}&client_secret={1}&&'\
'grant_type=client_credentials'.format(CLIENT_ID, CLIENT_SECRET)
#Get the generated token
token = session.get(baseUrl + tokenPath).json()['access_token']
event = session.get(baseUrl, params={
"ids": "event_id",
"fields": ",".join(fields),
"access_token": token,
}
).json()
print(event["name"])
print(event["place"])
You can make a facebook app here which is where the CLIENT_ID & CLIENT_SECRET come from.
Why would you use URL requests and not the SDK?
Using the SDK the generated user access tokens expire every day, its possible to extend them but only for 60 days. If you want to use the SDK it has a method built in which allows you to extend the token, in order to extend the token you also need to create a facebook app. Its also possible to extend tokens using this website, though I cant vouch for its security - it could potentially access and exploit your data.
To extend the token with SDK:
import facebook
graph = facebook.GraphAPI(user_access_short_lived_token)
extended_token = graph.extend_access_token(app_id, app_secret)
print(extended_token)
Using the URL approach, you create a client access token at runtime (read about user access token vs client access token here) and the token is valid so long as your app is active. So if you are going to use this a lot or want to create it and not have to change/extend tokens then use the URL approach.
Hope this gets you started.

how to use Time-based Pagination with Facebook graph api v2.x

As the link below said that we could get a time based paging result :
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.4
My problem is ,how could i make a request so can i received a result like that ?
anyone could help me , thanks anyway !
finally i find the answer is :
not all the node in Facebook open graph support time-based paging , such as likes
the official example node which support it is feed
so you can get a time-based paging result if you send request like this:
https://graph.facebook.com/v2.4/me/feed?limit=20&&since= 1420041600
or :
https://graph.facebook.com/v2.4/me/feed?limit=20&&until= 1420048600
dose anyone has a more specified answer about it ?

Twython : cursor on statuses/get_user_timeline returns my tweets instead of screen_name passed

I started using Twython recently and was impressed by the simplicity. Thanks for the developing and maintaining the library.
However, when I tried running a cursor on get_user_timeline() endpoint, I got my timeline instead of the user specified in the 'screen_name' parameter. I ran the following with App auth.
twitter = Twython(APP_KEY, access_token=self.ACCESS_TOKEN)
tweets = twitter.request("https://api.twitter.com/1.1/statuses/user_timeline.json", "GET", {'screen_name': '<some screen name>'})
that worked just fine for 20 tweets or 1 page worth of tweets.
I am wondering then why my below stated code did not work?
twitter = Twython(APP_KEY, access_token=self.ACCESS_TOKEN)
tweets = twitter.cursor(twitter.get_user_timeline, {"screen_name":"narendramodi"})
Am I using the cursor wrong? If so what would be an ideal way of using the endpoint in question.
Thanks for your answers in advance!
Thanks and Regards,
Atul.
This problem of getting the tweets from the authenticated user happened to me before. The reason was that I was giving as argument an non-existent user. Make sure you don't confuse the name with the screen-name.

How can I export the feed from a group using Graph API?

I want to export the data of my Facebook group to some sort of file for historical purposes. I understand how to use the API but I don't know what I need to do to work with it. I can make queries in the explorer but it takes way to long for it to execute. I want to know what I need to do to export the data from my group into say a text file. Even just the basic steps in order to use the API would help. Thanks
You'll need to use one of the Facebook SDK's in order to programmatically access the Facebook API. Some popular ones are the JavaScript and PHP SDK's. The docs for each contain how to make API calls, and then you can use your code to handle the response to do whatever you want with them (as long as you stay within Facebook's policies).
An example of an API call in Facebook would be (after loading the SDK and having a valid login):
FB.api('/me', function(response) {
alert(response.name);
});
Let me know if that makes sense, or if you're still unclear how to approach API calls.
You have to get the feeds of the group first using graph api. Here is the code for that.
$groupFeeds = $facebook->api('/GROUP_ID/feed/?access_token='.$accessToken);
Note : $facebook is the object created of facebook class.
You have get the access token. Also you have should have the user_group permissions to extract the feeds of group.