Python facebook windows app not allow - python

My program download some infos about user and post it to the label in app.
I have a interaction/authorization problem with gui Facebook app in python. My app uses tkinter, facebook and fbconsole.
I autorized in this way.
import fbconsole as F
F.APP_ID="123"
F.AUTH_SCOPE=['publish_stream', 'publish_checkins', 'read_stream', 'offline_access']
F.ACCESS_TOKEN = "1234"
F.authenticate()
And something for show results
newsfeed = F.get('/me/home', {'fields':'from,name,description,message'})
newsfeedData = newsfeed["data"]
label.config(text=newsfeedData)
But when I run it, appear new facebook tab in browser announce: "Application configuration does not allow the use of the URL". How can I get rid of it?
Thanks!

Related

"accounts.spotify.com sent an invalid response" Spotipy API

Coding on VScode and on Windows 11
Hi everybody. I was very excited when I discovered the potential of the Spotify's API. However I'm still struggling with the authentication step. I'm trying to connect to my own spotify account so far.
Bellow is the basic code I was trying to run:
`
import spotipy
import spotipy.util as util
my_username = "47tol*******************h7en8"
my_scope = "user-library-read"
token =util.prompt_for_user_token(username = my_username,
scope = my_scope,
client_id = "5e5197d3dd2c4a52bdad0bead149c334",
client_secret = "7t********************14",
redirect_uri = "http://797096755318371914146942828329574")
sp = spotipy.Spotify(auth = token)
user = sp.current_user()
print(user["display_name"])
print(user["followers"]["total"])
`
This kind of works and properly open the web browser (chrome) but the spotify logging page shows "accounts.spotify.com sent an invalid response"
enter image description here
I have tried everything but can't get by this issue.
Right before, on the same computer, I have run this code
`
import spotipy
from spotipy.oauth2 import SpotifyOAuth
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id="5e5197d3dd2c4a52bdad0bead149c334",
client_secret="7t********************14",
redirect_uri="http://797096755318371914146942828329574",
scope="user-library-read"))
user = sp.current_user()
print(user['display_name'])
print(user['followers']['total'])
`
It opened the browser, I confirmed the connexion (my spotify account is connected on chrome), then the following code run smoothly.
I read maybe the connexion token has been saved on my computer so maybe I can't connect twice the same account to my App through the API??? Anyway I've tried :
`
os.remove(f".cache-{my_username}")
`
But it couldn't be able to find the file so I guess the problem is not that the token was already stored on my computer.
I then tried to run this code on another computer. The chrome page to connect to spotify opened well, I click on connect. Then the "accounts.spotify.com sent an invalid response" show up again and I'm back at the same point.
I you have some hint I'll be glad to read you. Many thanks
PS: The user name is mine. It is shown like this when on my spotify account (the one to listen to music) i click on "copy link to profile". I think it's because I create my account through a facebook account. I have also tried my "proper" spotify username but doesn't work neither.

Trying to Scrape Reddit with praw.Reddit

Im trying to scrape Reddit with the praw.reddit command and I keep getting the following:
prawcore.exceptions.OAuthException: unauthorized_client error processing
request (Only script apps may use password auth)
Heres the top of my code:(I removed the sensitive items)
import praw
import pandas as pd
import datetime as dt
reddit = praw.Reddit(client_id='zlpcoz08aNK8Bw', \
client_secret='', \
user_agent='comment_scraper 1.0 by /u/bullybear77777',
\
username='', \
password='')
I think it's because of my user_agent ID? I looked online and found that this appears to be the structure but im not sure. Any helps here would be greatly appreciated
This sort of error is caused by the type of app associated with that client id. Logging in with a password is restricted to script type apps.
When you create a new application, there are three types of apps to choose from:
web app: A web based application
installed app: An app intended for installation, such as on a mobile phone
script: Script for personal use. Will only have access to the developers accounts
If the application has the web app or installed app types then this form of authentication can't be used. You can't change the app type once it's created, but you can simply create a new one with a script type.

How to get FB access_token from python console app?

I have a console application that should get a list of people who liked my page.
As far as I understood I should run something like
QUERY = 'SELECT user_id FROM like WHERE object_id=__MY_PAGE_ID__'
url = "https://graph.facebook.com/fql?q=" + QUERY
data = requests.get(url)
but iI need to use some access token, and I don't understand what kind of. I have log and pass for user with administrative rights on this PAGE. But thay said that I can't get user token without interacting with web browser.
So I need to use app? Should I create it before somehow? How can you allow this app to get admin account on the page?
Thanks

Alert message on Google App Engine for Python

I want to pop an alert message for error handling on an app that runs via Google App Engine for Python.
I tried this already but non worked:
from Tkinter import *
msg = Message(text="Please, make sure you fill out the boxes and agree with the terms")
msg.config(bg='green', font=('times', 16))
msg.pack()
mainloop()
AND
import win32api
win32api.MessageBox(0, 'hello', 'title')
I am guessing the Google App Engine has its own way of handling this task but I can't figure out how.
Thank you!
You can't do that. The GAE server suppose to run headless, so you can't display a popup in your host machine. If you use windows to launch de dev server, simply use the log buton from the GUI or launch your dev server from the command line.
To generate a debug log from your application you can simply see this post. Google app engine logging in dev consol
In production your application have a full admin panel with a lot of possibilities and a logging pannelto see all messages from your app.

Get facebook user/app token in a python desktop app

I am writing a python desktop app that will access a user's facebook photos. The app currently supports flickr, which uses a similar oauth authentication process, but I am struggling to figure out how to authenticate the app for facebook. For flickr, the basic steps are:
App opens a browser on the authentication page
user gives the app permission to access the account
App receives a token as a http response that can then be used with flickr's api
I am hoping that there is something similar for facebook, but I haven't been able to figure it out.
There are a variety of facebook API libraries for python, such as Pyfb, which provides a simple way of accessing graph data, but none of them provide an obvious way to do the authentication steps above and retrieve a token that can be used. Here's the example from Pyfb, which presumes that the user token will be manually entered by the user, which is totally ridiculous for a desktop app...
from pyfb import Pyfb
#Your APP ID. You Need to register the application on facebook
#http://developers.facebook.com/
FACEBOOK_APP_ID = 'YOUR_APP_ID'
pyfb = Pyfb(FACEBOOK_APP_ID)
#Opens a new browser tab instance and authenticates with the facebook API
#It redirects to an url like http://www.facebook.com/connect/login_success.html#access_token=[access_token]&expires_in=0
pyfb.authenticate()
#Copy the [access_token] and enter it below
token = raw_input("Enter the access_token\n")
#Sets the authentication token
pyfb.set_access_token(token)
#Gets info about myself
me = pyfb.get_myself()
Here's a shot at answering my own question.
First, the reason the code fragment above doesn't work. The call to pyfb.authenticate opens the authentication link in the default browser. After the user logs in and allows the app access, facebook is supposed to redirect the URL in the browser to something like
https://www.facebook.com/connect/login_success.html#access_token=ACCESS_TOKEN&
expires_in=SOMETIME
In the pyfb code sample, the user is supposed to copy the access token from the URL bar and all should be well. But... presumably because of some security concerns, facebook will perform some Javascript shenanigans which will instead leave you with:
https://www.facebook.com/connect/blank.html#_=_
(It turns out that you can work around this by digging through the browser history on some browsers -- see https://bugs.kde.org/show_bug.cgi?id=319252)
The solution to this for a desktop app is to open a web view within the app. The Javascript code apparently will correctly detect you are authenticating within an app and spit out the full URL with token. So here's an example using Python gtk and webkit:
import gtk
import webkit
view = webkit.WebView()
sw = gtk.ScrolledWindow()
sw.add(view)
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
win.add(sw)
win.show_all()
win.connect("destroy", lambda *args:gtk.main_quit())
client_id = 'XXXXXXXXXXXXX' #your unique app id
auth_url = 'https://www.facebook.com/dialog/oauth?response_type=token&client_id=%s&redirect_uri=https://www.facebook.com/connect/login_success.html'%(client_id,)
view.open(auth_url)
def load_finished(view,frame):
#function will print the url with token second time
print frame.get_uri()
view.connect("document-load-finished",load_finished)
gtk.main()

Categories