Me and my friend are working on an fan app for a friends band and it's supposed to pull their facebook page feed/statuses into a tableView but it only returns one empty cell. Since the app is a secret i linked to the graph for ansca, the bands graph looks just like this one.
https://developers.facebook.com/tools/explorer?method=GET&path=79415735871%2Ffeed
I don't know why it only returns one cell, if I use "me/friends" and follow the corona docs then it returns all my friends.
edit: Updated and edited the code.
Thanks/David
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local widget = require("widget") local json = require("json") local facebook = require("facebook") ----------------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION -- -- NOTE: Code outside of listener functions (below) will only be executed once, -- unless storyboard.removeScene() is called. -- -------------------------------------------------------------------------------------- local facebookAppId = "xxxxxxxxxxxxxxxx" local facebookUserId = "xxxxxxxxxxxxxx" local anscaID = "79415735871" local response local data local myTableView; -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view local tableViewOptions = { top = 64, left = 0, width = 320, height = 368, friction = 0.935, -- maskFile = "assets/masks/mask-370.png" } myTableView = widget.newTableView(tableViewOptions) group:insert(myTableView) local fbLogin = function(event) if event.type == "session" and event.phase == "login" then facebook.request(anscaID.."/statuses") elseif event.type == "request" then response = json.decode(event.response) data = response.data for i = 1, #data do local function onRowRender( event ) local row = event.target local rowGroup = event.view local userName local pubDateText local messageText local likesCount row.userName = display.newRetinaText(rowGroup, data[i].from.name, 0, 0, "Helvetica-Bold", 14) row.userName:setReferencePoint(display.TopLeftReferencePoint) row.userName.x = 10 row.userName.y = 5 row.userName:setTextColor(33, 33, 33, 255) row.messageText = display.newRetinaText(rowGroup, data[i].message, 0, 0, 300, 88, "Helvetica", 12) row.messageText:setReferencePoint(display.TopLeftReferencePoint) row.messageText.x = 10 row.messageText.y = row.userName.height +15 row.messageText:setTextColor(66, 66, 66, 255) row.pubDateText = display.newRetinaText(rowGroup, data[1].updated_time, 0, 0, "Helvetica", 12) row.pubDateText(display.TopLeftReferencePoint) row.pubDateText.x = 10 row.pubDateText.y = row.messageText.height +15 row.pubDateText(66, 66, 66, 255) row.likesCount = display.newRetinaText(rowGroup, data[1].likes.count, 0, 0, "Helvetica", 12) row.likesCount(display.TopLeftReferencePoint) row.likesCount.x = row.pubDateText.width + 30 row.likesCount.y = row.messageText.height +15 row.likesCount(66, 66, 66, 255) end --onRowRender closed local rowHeight = 128; local lineColor = {0, 0, 0, 255} local rowColor = {255, 255, 255, 255} myTableView:insertRow{ height = rowHeight, lineColor = lineColor, rowColor = rowColor, onRender = onRowRender } end--for ends end end facebook.login( facebookAppId, fbLogin, {"read_stream"}) -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view -- Do nothing end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view -- INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.) end -- If scene's view is removed, scene:destroyScene() will be called just prior to: function scene:destroyScene( event ) local group = self.view -- INSERT code here (e.g. remove listeners, remove widgets, save state variables, etc.) end ----------------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION ----------------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched whenever before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) ----------------------------------------------------------------------------------------- return scene |
Try changing :
1 2 | response = event.response response = json.decode(event.response) |
Thanks Danny,
I realized that too after a while but there are some problems still.
When I start the app it fetch the data from facebook I requested but not all of it, some posts have no date and some no message and the user name never returns. Some cells are empty (happens with "me/friends" too). This only works with "me/statuses" and not "me/feed"
I have extended permissions etc to fetch everything I need but this is driving me crazy because from what I understand I can change me to any user I want and get their statuses if their profile is public.
Another problem is that it only returns the data every other time and I have to remove the app permission from my facebook for it to reload the statuses and it's not every time it fetch the data either.
Last but not least, I use this in a tabBar app and when I switch tabs back and forth the tableview gets removed. What would cause that, because I don't remove it?
David,
try save the response data to a local file and then read from there to populate the tableView. If you do that then you can check sandbox if you get all data you request/have permissions to read.
Danny
Well, I did print the event.response and it shows the ansca status updates, however as adviced I tried to write the content to a file but it does not write nor does it populate the tableView anymore, what am I missing here?
Since json.decode returns a lua table called response and I write the lua table to the text file, should I instead write the event.response to a json file and decode that file instead?
Thanks guys.
David
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local widget = require("widget") local json = require("json") local facebook = require("facebook") ----------------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION -- -- NOTE: Code outside of listener functions (below) will only be executed once, -- unless storyboard.removeScene() is called. -- -------------------------------------------------------------------------------------- local facebookAppId = "xxxxxxxxxxxxxxxx" local facebookUserId = "xxxxxxxxxxxxxx" local anscaID = "79415735871" local response local data local myTableView; -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view local tableViewOptions = { top = 64, left = 0, width = 320, height = 368, friction = 0.935, -- maskFile = "assets/masks/mask-370.png" } myTableView = widget.newTableView(tableViewOptions) group:insert(myTableView) local fbLogin = function(event) if event.type == "session" and event.phase == "login" then facebook.request(anscaID.."/statuses") elseif event.type == "request" then response = json.decode(event.response) data = response.data local path = system.pathForFile( "fbData.txt", system.DocumentsDirectory ) -- io.open opens a file at path. returns nil if no file found local file = io.open( path, "r" ) if file then -- read all contents of file into a string local contents = file:read( "*a" ) io.close( file ) else -- create file b/c it doesn't exist yet file = io.open( path, "w") file:write(response) io.close( file ) end for i = 1, #data do local function onRowRender( event ) local row = event.target local rowGroup = event.view local userName local pubDateText local messageText local likesCount row.userName = display.newRetinaText(rowGroup, data[i].from.name, 0, 0, "Helvetica-Bold", 14) row.userName:setReferencePoint(display.TopLeftReferencePoint) row.userName.x = 10 row.userName.y = 5 row.userName:setTextColor(33, 33, 33, 255) row.messageText = display.newRetinaText(rowGroup, data[i].message, 0, 0, 300, 88, "Helvetica", 12) row.messageText:setReferencePoint(display.TopLeftReferencePoint) row.messageText.x = 10 row.messageText.y = row.userName.height +15 row.messageText:setTextColor(66, 66, 66, 255) row.pubDateText = display.newRetinaText(rowGroup, data[1].updated_time, 0, 0, "Helvetica", 12) row.pubDateText(display.TopLeftReferencePoint) row.pubDateText.x = 10 row.pubDateText.y = row.messageText.height +15 row.pubDateText(66, 66, 66, 255) end --onRowRender closed local rowHeight = 128; local lineColor = {0, 0, 0, 255} local rowColor = {255, 255, 255, 255} myTableView:insertRow{ height = rowHeight, lineColor = lineColor, rowColor = rowColor, onRender = onRowRender } end--for ends end end facebook.login( facebookAppId, fbLogin, {"read_stream"}) -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view -- Do nothing end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view -- INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.) end -- If scene's view is removed, scene:destroyScene() will be called just prior to: function scene:destroyScene( event ) local group = self.view -- INSERT code here (e.g. remove listeners, remove widgets, save state variables, etc.) end ----------------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION ----------------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched whenever before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) ----------------------------------------------------------------------------------------- return scene |
Hi David.
You can use this function to save a table (using json)
1 2 3 4 5 6 7 | local function saveTable(fp, theTable) local path = system.pathForFile(fp, system.DocumentsDirectory) file = io.open(path, "w") file:write(json.encode(theTable)) io.close(file) end |
Danny,
But why put it in a function like that?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | local fbLogin = function(event) if event.type == "session" and event.phase == "login" then facebook.request(anscaID.."/statuses") elseif event.type == "request" then response = json.decode(event.response) local path = system.pathForFile("fbData.json", system.DocumentsDirectory) file = io.open(path, "w") file:write(json.encode(response)) io.close(file) end end |
Danny,
Just tried this too and no file was created.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | local response = {} local fbLogin = function(event) if event.type == "session" and event.phase == "login" then facebook.request(anscaID.."/statuses") elseif event.type == "request" then response = json.decode(event.response) end end local function saveTable() local path = system.pathForFile("fbData.json", system.DocumentsDirectory) file = io.open(path, "w") file:write(json.encode(response)) io.close(file) end |
This is an odd one, I will check out your code on my computer first thing in the morning for you and try and get this resolved
send message and call to a person
Forum: Report Spam + PM
[INSTALL_PARSE_FAILED_NO_CERTIFICATES]
[SOLVED] Director ERROR: Failed to execute new( params ) function on 'screen1'
Too many (200) local variables
Corona SVG Level Builder released. Drag and drop physics level editor with Inkscape and SVG.
Small bug in Collectible Items example
Pivot Joints and apparent elasticity
Can't make removeSelf() delayed
Just found screen casting with Jing
problem accessing data in modules
Ui Label / Button Question!
How to create iOS Apps, not only Android apps.
removing random objects
can not install apk on Galaxy S 2
scrollView:scrollToX() not working?
Is there a way to play an audio stream?
Need help with corona registration