FQL error 'failed to open stream failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error in ' - facebook-php-sdk

I am 2 facebook accounts.
I use one for testing (has 600 friends) and other for development (5 friends). I am trying get all the ids of a users friend using the code
function get_photo($access_token){
// Run fql query
$fql_query_url = 'https://graph.facebook.com/'
. '/fql?q=SELECT+pid+,object_id+,owner+FROM+photo+WHERE+owner+=+me()+OR+owner+IN+(SELECT+uid2+FROM+friend+WHERE+uid1+=+me())+LIMIT+50'
. '&access_token=' . $access_token;
// First logically check the result, TRUE: Result is passed to $fql_query_result.
// FALSE: $flq_query_result = 0 or false.
$fql_query_result = file_get_contents($fql_query_url)?file_get_contents($fql_query_url):0;
// Only json_decode the result if it was valid.
$fql_query_obj = (!$fql_query_result == 0) ? json_decode($fql_query_result, true) : "FQL was not a valid query";
//display results of fql query
echo '<pre>';
//print_r("query results:");
print_r($fql_query_obj);
echo '</pre>';
return $fql_query_obj;}
I have obtained the following permissions
user_about_me,read_stream,user_activities,email,user_location,user_photos,friends_photos,publish_actions,user_birthday,user_likes,read_insights,read_insights,user_status';
The problem is the code works from the developers account but gives the following error with the test account.
file_get_contents(https://graph.facebook.com//fql?q=SELECT+pid+,object_id+,owner+FROM+photo+WHERE+owner+=+me()+OR+owner+IN+(SELECT+uid2+FROM+friend+WHERE+uid1+=+me())+LIMIT+50&access_token=AAAEEKwQN3CMBAEUC6DqfakwkSZCdeLI2zk5Ec2evZBJvZB14Nh9e4ZBs8bOOw36F9T2winWRyzSx3vSCcWOl4A80AgcOjEvft1sbW7MLeEE2cyVPCIAb): failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error in /var/www/JMJ_test/facebook_include1.php on line 190
FQL was not a valid query

I have found this problem with other APIs. Normally, it's nothing wrong with the code, but the amount of friends on the account. The dev one works, only 5 friends, whereas the testing one doesn't because it has 600 friends. I will try and find the limit for you in a second.
Edit
Sorry, I could not find the limit, but I read something about 600 requests per 600 seconds per iP. Not sure if that has anything to do with it.

Related

Wikidata Forbidden Access

I was trying to run some wikidata queries with Python requests and multiprocessing (number_workers = 8) and now I'm getting code 403 (Access Forbiden). Are there any restrictions? I've seen here that I should limit myself to 5 concurrent queries, but even with one query I don't get any result now through Python. It used to work.
Is this Access Forbiden temporary or am I blacklisted forever? :(
I didn't see any restrictions in their doc, so I was not aware that I'm doing something that will get me banned.
Does anyone know what the situation is?
wikidata_url = 'https://query.wikidata.org/sparql'
headers = {'User-Agent': 'Chrome/77.0.3865.90'}
r = requests.get(wikidata_url, params={'format': 'json', 'query': query, 'headers': headers})
EDIT AFTER FIXES:
It turned out that I was temporarily banned from the server. I have changed my user agent to follow the recommended template and I waited for my bad to be removed. The problem was that I was ignoring the error 429 that tells me that I have exceeded my allowed limit and I have to retry after some time (some seconds). This leaded to my error 403.
I tried to correct my error caused by inexperience by writing the following code that takes this into account. I added this edit because it may be useful for someone else.
def get_delay(date):
try:
date = datetime.datetime.strptime(date, '%a, %d %b %Y %H:%M:%S GMT')
timeout = int((date - datetime.datetime.now()).total_seconds())
except ValueError:
timeout = int(date)
return timeout
def make_request(params):
r = requests.get(wikidata_url, params)
print(r.status_code)
if r.status_code == 200:
if r.json()['results']['bindings']:
return r.json()
else:
return None
if r.status_code == 500:
return None
if r.status_code == 403:
return None
if r.status_code == 429:
timeout = get_delay(r.headers['retry-after'])
print('Timeout {} m {} s'.format(timeout // 60, timeout % 60))
time.sleep(timeout)
make_request(params)
The access limits were tightened up in 2019 to try and cope with overloading of the query servers. The generic python-request user agent was blocked as part of this (I don't know if/when this was reinstated).
Per the Query Service manual, the current rules seem to be:
One client (user agent + IP) is allowed 60 seconds of processing time each 60 seconds
One client is allowed 30 error queries per minute
Clients who don't comply with the User-Agent policy may be blocked completely
Access to the service is limited to 5 parallel queries per IP [this may change]
I would recommend trying again, running single queries with a more detailed user-agent, to see if that works.

CMIS connection issue

cannot tell if this issue is the same as some others posted. ours simply throws a msg, but it appears CMIS connection related - our application uses CMIS/Alfresco. i am not very familiar, but we have a server related to it. not sure if a power outage is related to the fact that we this error[pwr outage yesterday, then mysteriously this error was later noticed]. we normally post information on the web page that is populated by our sql data[a table field populates a textarea/text editor] - instead we get the error above: "CMIS connection issue". that verbiage comes from a file that instantiates connection with CMIS, here is the related code:
//Check cmis service connect or not
try{
$client = new CMISService($repo_url, $repo_username, $repo_password);
}catch (Exception $ec) {
echo "CMIS connection issue";
echo "<br >\n" ;
echo $ec->getMessage() ;
die;
}
the CMISService parms have not changed, and they appear to be proper values. i even tried "admin", and "root" as "repo_username" in addition to the defined username.
Ideas on what we can check?

Angular 2 always returns http status code 200 on this.http.get() even if the file doesn't exist

i'm trying to check if a pdf file exists on the server with an HTTP get request,for that i am testing if the status code returned by the server's response is different then 200, the problem is that i always get status code 200 and statusText "OK".
here's my Service class
getPdf(year: number,type: number, num: number): boolean{
this.http.get('http://localhost:4200/app/pdfs/'+year+'/'+type+'/'+num+'.pdf')
.subscribe(data => console.log(data));
return true;
}
in my component i have this code :
ngOnInit(){
this.pdfService.getPdf(2016,71015,1275);
}
and that's the result i get in Chrome dev tools console
any ideas of why that is happening and how i can check the existance of a file if this method is not applicable?
I think your server is redirecting some or all requests for assets not found to your main page. It is somewhat common for a single page app. You need to update your server configurations to make it return a not found response for some folders at least.

php facebook sdk want to create subscription for real-time updates

got this error every time if I change verify_token value or server request method.
{"error":{"message":"(#2201) response does not match challenge, expected value = '1383165001', received=''","type":"OAuthException","code":2201}}{"data":[]}
Your script just needs to return the challenge back to Facebook, so it can verify the response. I do the following in my script:
// return hub.challenge to facebook
echo isset( $_GET['hub_challenge'] ) ? $_GET['hub_challenge'] : false;
It basically just echos the challenge sent by Facebook back to it.

MSXML2.XMLHTTP Request to validate entered URL in ASP Classic

Thanks in advance for any help received.
I want to allow our client to enter a URL into a text field which then checks whether the URL exists and works.
There are 3 possible outcomes I want to check for:
A status of 200 - OK,
A status of 500 - Server Error,
Or a status of 404 - page not found.
When executing the following code in ASP classic I get a status code of 12007 when I should be getting 404. Is this because it can't find a webserver to return a code of 404?
Function CheckURL(vURL)
ON ERROR RESUME NEXT
Set oXML=Server.CreateObject("MSXML2.XMLHTTP") : oXML.Open "POST",vURL,false : oXML.Send()
CheckURL = oXML.status
Set oXML = nothing
End Function
Or is something amiss here. What status codes am I likely to see other than the standard mentioned above.
The 12007 is a Windows HTTP error which means name hasn't been resolved. You can't get a 200, 404, 500 or any such thing if the host name can't be resolved to an IP address or a connection can't be established to that IP address. In these cases you will get error codes in the 12000s range which aren't HTTP status codes but are windows exception numbers.
See this list for a list of these exception numbers.
BTW, XMLHTTP is not a safe item object to use in ASP. Also why are you using a POST? This is the code I would use:-
Function CheckURL(vURL)
On Error Resume Next
Set xhr = CreateObject("MSXML2.ServerXMLHTTP.3.0")
xhr.Open "HEAD", vURL, false
xhr.Send
CheckURL = xhr.status
End Function
Using HEAD allows you test the URL without actually downloading a potentially large entity body.

Resources