I have had some trouble with fetching json from a groups events on facebook and then put them in a tableview to be used in a Appcelerator mobile app.
The idea is to have this as a calendar to show events for a club in a simple way.
I want to show the name of the event. The picture for that event and the date for the event.
All in a tablerow.
I have gotten to the part where i can get the Name and date for the events with this code:
Ti.UI.backgroundColor = '#dddddd'; var access_token='AAACEdEose0cBAAICGa4tFTcZAqCOGm2w9qPYGZBwNtJ1oZAcwaMAP2DDHZCN58cvVBZCHZADZAZBTPC8tTnpfQ7uGKI5j3SbMYcRmWquZCdPzhwZDZD'; var url = "https://graph.facebook.com/64306617564/events?&access_token=" + access_token ; var win = Ti.UI.createWindow(); var table = Ti.UI.createTableView(); var tableData = []; var json, data, row, name, start_time, id; var xhr = Ti.Network.createHTTPClient({ onload: function() { // Ti.API.debug(this.responseText); json = JSON.parse(this.responseText); for (i = 0; i < json.data.length; i++) { data = json.data[i]; row = Ti.UI.createTableViewRow({ height:'60dp' }); var name = Ti.UI.createLabel({ text:data.name, font:{ fontSize:'18dp', fontWeight:'bold' }, height:'auto', left:'50dp', top:'5dp', color:'#000', touchEnabled:true }); var start_time = Ti.UI.createLabel({ text:'"' + data.start_time + '"', font:{ fontSize:'13dp' }, height:'auto', left:'15dp', bottom:'5dp', color:'#000', touchEnabled:true }); row.add(name); row.add(start_time); tableData.push(row); } table.setData(tableData); }, onerror: function(e) { Ti.API.debug("STATUS: " + this.status); Ti.API.debug("TEXT: " + this.responseText); Ti.API.debug("ERROR: " + e.error); alert('There was an error retrieving the remote data. Try again.'); }, timeout:5000 }); xhr.open("GET", url); xhr.send();But when i want the specific event to open in a new window when clicked i just get the event that lies last on the screen when i put this in a browser:
https://graph.facebook.com/64306617564/events?&access_token=AAACEdEose0cBAOLAFWMKPmvgqEwap1ldnl7DeZBDKJC6YTZC4Goh6K5NHsvpOFmFQaGp1IekVsCxZCZCz3lwGpRcQG9ZBkcMrZAnLk4As8kgZDZD
And the access token expires REALLY fast. Any ideas how to make an access token that lasts longer?
Well, the code i am using to open the window is:
table.addEventListener('click',function(e) { // Create the new window with the link from the post var blogWindow = Ti.UI.createWindow({ title : data.name, modal : true, barColor: '#050505', backgroundColor: '#050505' }); var webView = Ti.UI.createWebView({url:'http://www.facebook.com/events/' + data.id}); blogWindow.add(webView); // Create the close button to go in the left area of the navbar popup var close = Titanium.UI.createButton({ title: 'Close', style: Titanium.UI.iPhone.SystemButtonStyle.PLAIN }); blogWindow.setLeftNavButton(close); // Handle the close event close.addEventListener('click',function() { blogWindow.close(); }); blogWindow.open(); }); win.add(table); win.open();in my opinion that should open the event that is clicked on by parsing the ID from the row and putting it after the link.
Am i stupid or what is wrong?
It doesnt matter on which event i click it just open the last one all of the times.
And how can i get a thumbnail for the events?
Do iget the user to login to get seperate access tokens?
If so how do i do that?
Pls help.....
//R
2 Answers
Hi,
I suppose you can make use of Graph API, below was a sample app developed by Ben for CodeStrong2011
https://github.com/benbahrenburg/bARk
Look at the Facebook demo in KitchenSink to see how to handle logins and general flow and then performing things on the FB Graph API on the user's behalf.
Don't put the access code in your app. One will be set after the user logs in.
Don't forget to add the Facebook app ID in the tiapp.xml (as in KS for their app id)
Your Answer
Think you can help? Login to answer this question!