Get Downloads from github via php api - github

I'm trying to get all downloads from an repo on github with help of https://github.com/ornicar/php-github-api
There is no download Object in this project, so i've created my own:
class Github_Api_Download extends Github_Api{
public function getDownloads($repo, $username){
$string = 'repos/'.urlencode($username).'/'.urlencode($repo).'/downloads';
$response = $this->get($string);
die(print_r($response));
return $response;
}
}
When i run this, i'm getting only
Server Error
HTTP 401: Unauthorized
it should be possible to get this without authentication too, because if i use the url in the browser, it's working
my authentication is working, because all the actions (e.g. create new repo,etc..) are working fine
Anybody can help me?:)

I was looking for this earlier, so I wrote my own little function and posted it on my blog. Hope this helps.
Check this out

Related

Can't display Facebook user avatar with Facebook API and Graph

I'm working in a React-Native app, and I'm also allowing users to login using FBSDK.
There seems to be an issue at the moment when trying to get the profile picture URL.
There are also several reports of this, like this one but still, after a year doesn't seem to be solved.
Attempted many ways but none worked, it always tries to download the file, seems it's missing the mime-type according to what the browser says.
The URL it gives is the following:
https://platform-lookaside.fbsbx.com/platform/profilepic/?asid={{myfbid}}&height=50&width=50&ext=1583348357&hash=AeTnFpMVwBXgFy_J
Also tried using the graph url directly: http://graph.facebook.com/{myid}/picture
And if I add the &redirect=false, it returns a data object with the platform-lookaside URL.
Everything I try, it tries to download.
This is how I'm currently trying to get the image using Graph API.
new GraphRequestManager().addRequest(new GraphRequest(
'/me',
{
accessToken: fbToken,
parameters: {
fields: {
string: 'picture.type(large)'
}
}
},
graphRequestCallback
)).start();
It works, but the URL is the same.
Any idea on how can I solve this? I might be missing something or the bug is still happening?
If you just change the graph url (http://graph.facebook.com/{myid}/picture) from http to https, it should work for you. Not sure if that's a new fix in React Native or not, but that solved it for me.

flask-jwt-extended - Catch raise RevokedTokenError('Token has been revoked')

I already tried reading the documents as well try out the changing default behaviors https://flask-jwt-extended.readthedocs.io/en/latest/changing_default_behavior.html to handle the error (the link shows how to handle expired token) and search around in google everything in every keyword combination i could do but seems no one has example about this.
I tried using #jwt.revoked_token_loader to handle the RevokedTokenError but it seems it doesn't work as I applied it like this
#jwt.revoked_token_loader
def revoked_token_response(revoked_token):
jwtkn = revoked_token['jti']
return jsonsify({
'msg': 'token {} already been revoked!'.format(jwtkn)
)}, 401
actually, i don't know exactly how does the example on the link to handle expired tokens had parameter of 'expired_token', is that self-declaration like what I did above on the 'revoked_token'?? as far as I know, 'jti' is like a default value in the flask-jwt-extended package as I see error whenever I don't use this (in my db, it is different but there is no problem at all.
I tried following this tutorial and it works out fine on my side (as well his original code source) but I see that this one doesn't have a catch exception also on Revoke Tokens https://codeburst.io/jwt-authorization-in-flask-c63c1acf4eeb
I use postman and if based on the tutorial link, here's how i get this
i do login
i use the access token generated to access protected routes ('/secrets')
i do logout
i use again the access token generated to access protected routes
after the last one, i get this error on my server side (ide):
....flask_jwt_extended\utils.py", line 216, in verify_token_not_blacklisted
raise RevokedTokenError('Token has been revoked')
flask_jwt_extended.exceptions.RevokedTokenError: Token has been revoked
127.0.0.1 -- [02/Jul/2019 22:25:26] "GET /secrets HTTP/1.1" 500 -
in postman, this is what I get:
{
'message': 'Internal Server Error'
}
my target is to send out a custom json response instead of 'Internal Server Error'
edit:
I am no wiz on programming or such, a beginner that wanted to practice out python about secured web development. I don't yet quite understand still how decorator works out in terms of application, etc. so i don't know if others tweaks out the flask-jwt-extended package to work such things out.
Getting back a 500 error normally occurs because of a bug in other flask extensions and how that interact with native flask errorhandlers. You can find a bunch of discussions about it here (https://github.com/vimalloc/flask-jwt-extended/issues/86), but the tl;dr version is you might need to set app.config['PROPAGATE_EXCEPTIONS'] = True if using something like Flask-Restul, or use a hack like this if using flask-restplus:
jwt = JWTManager(app)
api = Api()
jwt._set_error_handler_callbacks(api)
If those don't help you, please take a look through that linked github issue, and if nothing in there helps make a reply in that issue detailing your setup.
Cheers.

Throwing 404 error with the authoriseUrl generated from GetRefreshToken

I am trying to create a sample project which consumes DFP services.
Till now :
Still in authentication part :
a) Successfully created clientId, while creating new Client Id have checked installed apps options in the Google developer console.
b) Added the clientId, clientSecret to ads.properties .
Note : Took dfp-axis-jars-and-examples-2.2.0.tar and making my changes in it[by importing project in IDE].
c) I ran into trouble while trying to paste the authoriseUrl in the browser after running GetRefreshToken.
Please find below the error :
"The redirect URI in the request: urn:ietf:wg:oauth:2.0:oob can only
be used by a Client ID for native application. It is not allowed for
the 'WEB' client type. You can create a Client ID for native
application in the Credentials section of the Google Developers
Console."
I believe I have selected the wrong applicationType while creating new ClientId .
Appreciate inputs .
The above answer did not make much sense at first glance but, I have resolved this issue by simply setting a value for redirectUri. So inside of my GetRefreshToken.php file
$redirectUri = "http://same_url_as_the_one_listed_in_console";
After closing looking at the authoriseUrl, it seemed I was sending the wrong redirectUrl.
I forgot to copy paste the redirectUrl generated from the creation of client id in the GetRefreshToken callback property:
private static final String CALLBACK_URL = "https://www.example.com/oauth2callback";//"urn:ietf:wg:oauth:2.0:oob";
No error now :).

Create Ticket using Freshdesk api, response is always { “logout”: “success” }

Well, I have tried every thing mentioned in Fresh-desk API (http://freshdesk.com/api#create_ticket) to create new ticket but with no success.
Even though i am able to create a new ticket from a Curl request, but when i use a browser REST client it says:
{
"logout": "success"
}
I have used the following : https://companyname.freshdesk.com/helpdesk/tickets.json
Headers: Content-type:application/json Authorization:(Basic Authorization using APIKEY:X)
{ "helpdesk_ticket":{ "description":"No ticket is created ...", "subject":"Support needed..", "email":"anything_xyz#gmail.com", "priority":1, "status":2 } }
I have tried clearing my browser cache many times. But the issue remains the same. Please someone suggest.
What kind of REST-Client do you use?
I was facing the same problem as I used the REST-Client Postman (=Chrome Browser extension). Clearing the browers cache solved that issue for me.

Facebook authentication tutorial missing piece

For the past 2 days I've been struggling trying to successfully authenticate users into my Facebook app. What I want to achieve in the end is to retrieve and store the access token of an user.
The problem I have comes by following the FB tutorial for authentication: http://developers.facebook.com/docs/authentication/
Just above the Client-side Flow section there is a snippet of code which should allow me to get the current user. Unfortunately, I only get an error:
Warning: file_get_contents(https://graph.facebook.com/me?access_token=) [function.file-get-contents]: failed to open stream: No route to host
Traced the error back to the point I can, and apparently there is an error on this line:
$response = #file_get_contents($token_url);
because if I echo the $response, I get nothing.
What is there not mentioned in the tutorial that I should be doing but I'm not because I have no idea I should do it?
Many thanks
You can achieve getting the access Token by
// Get the current access token
$access_token = $facebook->getAccessToken();
//And now echo the access token
echo $access_token;
Well, it got sorted in the end. Apparently it's a server problem. I tried developing the app on 2 different servers + locally (EasyPhp 5.3.8.1). On the 3rd server I tried it works for now (fingers crossed). Honestly, I have no idea why it's working now and why my local server didn't function as it should have. Well, it works for now :D