arze ramade
arze ramade

Reputation: 317

request empty result issue

I have this simple python code, which returning the content of URL and store the result as json text file named "file", but it keeps returning empty result . What I am doing wrong here? It is just a simple code I am so disappointed. I have included all the imports needed import Facebook,import request,and import json.

url ="https://graph.facebook.com/search?limit=5000&type=page&q=%26&access_token=xx&__after_id=139433456868"

content = requests.get(url).json()

file = open("file.txt" , 'w') 

file.write(json.dumps(content, indent=1))
file.close()

but it keeps returning empty result to me what I am missing here? here is the result:

"data": []

any help please?

Upvotes: 0

Views: 145

Answers (1)

sadaf2605
sadaf2605

Reputation: 7540

Its working fine:

import urllib2
accesstoken="CAACEdEose0cBACF6HpTDEuVEwVnjx1sHOJFS3ZBQZBsoWqKKyFl93xwZCxKysqsQMUgOZBLjJoMurSxinn96pgbdfSYbyS9Hh3pULdED8Tv255RgnsYmnlxvR7JZCN7X25zP6fRnRK0ZCNmChfLPejaltwM2JGtPGYBQwnmAL9tQBKBmbZAkGYCEQHAbUf7k1YZD"
urllib2.urlopen("https://graph.facebook.com/search?limit=5000&type=page&q=%26&access_token="+accesstoken+"&__after_id=139433456868").read()

I think you have not requested access token before making the request.

How to find access token?

def getSecretToken(verification_code):

token_url = ( "https://graph.facebook.com/oauth/access_token?" +
                      "client_id=" + app_id +
                      "&redirect_uri=" +my_url +
                      "&client_secret=" + app_secret +
                      "&code=" + verification_code )
response = requests.get(token_url).content

params = {}
result = response.split("&", 1)
print result
for p in result:
    (k,v) = p.split("=")
    params[k] = v
return params['access_token']

how do you get that verification code?

    verification_code=""
if "code" in request.query:
    verification_code = request.query["code"]

if not verification_code:
    dialog_url = ( "http://www.facebook.com/dialog/oauth?" +
                       "client_id=" + app_id +
                       "&redirect_uri=" + my_url +
                       "&scope=publish_stream" )
    return "<script>top.location.href='" + dialog_url + "'</script>"
else:
    access_token = getSecretToken(verification_code)

Upvotes: 2

Related Questions