Note that there are some explanatory texts on larger screens.

plurals
  1. POFlask - Can't get Facebook APP ID after changing project structure
    primarykey
    data
    text
    <p>I am creating a Facebook app in Flask. As this is a microframework I started simple from the tutorials and had everything in 2 files: app.py and conf.py (and others like /templates).</p> <p>In the basic structure (generated mostly by heroku) it was like this:</p> <pre><code>/game game.py conf.py </code></pre> <p>app.py</p> <pre><code>FB_APP_ID = os.environ.get('FACEBOOK_APP_ID') FB_APP_SECRET = os.environ.get('FACEBOOK_SECRET') requests = requests.session() app_url = 'https://graph.facebook.com/{0}'.format(FB_APP_ID) FB_APP_NAME = json.loads(requests.get(app_url).content).get('name') FB_APP_LOGO = json.loads(requests.get(app_url).content).get('logo_url') app = Flask(__name__) app.config.from_object(__name__) app.config.from_object('conf.Config') @app.route('/channel.html', methods=['GET', 'POST']) def get_channel(): return render_template('channel.html') @app.route('/') def index(): return 'index'+str(FB_APP_ID) if __name__ == '__main__': port = int(os.environ.get("PORT", 5000)) print requests.headers if app.config.get('FB_APP_ID') and app.config.get('FB_APP_SECRET'): app.run(host='0.0.0.0', port=port) else: print 'Cannot start application without Facebook App Id and Secret set' </code></pre> <p>conf.py</p> <pre><code>import os class Config(object): DEBUG = True TESTING = False LOG_LEVEL = os.environ.get('LOG_LEVEL', 'DEBUG') FBAPI_APP_ID = os.environ.get('FACEBOOK_APP_ID') FBAPI_APP_SECRET = os.environ.get('FACEBOOK_SECRET') FBAPI_SCOPE = ['user_likes', 'user_photos', 'user_photo_video_tags'] </code></pre> <p>I wanted to make it perfect MVC so I used <a href="http://flask.pocoo.org/docs/patterns/packages/" rel="nofollow">this link</a> and the problem started.</p> <pre><code>/game conf.py runserver.py /game /templates /static __init__.py views.py models.py </code></pre> <p>runserver.py</p> <pre><code>import os from game import app if __name__ == '__main__': port = int(os.environ.get("PORT", 5000)) # print requests.headers if app.config.get('FB_APP_ID') and app.config.get('FB_APP_SECRET'): app.run(host='0.0.0.0', port=port) else: print 'Cannot start application without Facebook App Id and Secret set' </code></pre> <p>__init__.py</p> <pre><code>from flask import Flask import os, requests, json SCRIPTS='static/scripts/' FB_APP_ID = os.environ.get('FACEBOOK_APP_ID') FB_APP_SECRET = os.environ.get('FACEBOOK_SECRET') requests = requests.session() app_url = 'https://graph.facebook.com/{0}'.format(FB_APP_ID) FB_APP_NAME = json.loads(requests.get(app_url).content).get('name') FB_APP_LOGO = json.loads(requests.get(app_url).content).get('logo_url') app = Flask(__name__) app.config.from_object(__name__) app.config.from_object('conf.Config') import game.views import game.models </code></pre> <p>conf.py stays the same and index view is in views.</p> <p>THE PROBLEM: In the first structure (simple) os.environ got all the FB_APP_ID and FB_APP_SECRET just fine, and I could do with the data whatever I want. </p> <p>Now (in the MVC) it just does not fetch the variables and what I have there is "None". I have tried to put the __init__ == __main__ wherever I could but nothing really worked.</p> <p>The conf.py has all the data put there in the beginning (like DEBUG=TRUE or LOG LEVEL). It's just the fb data that I don't get.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload