Comments (19)
@Pomax You've spelt 'master' wrong, but once corrected it seems to work fine for me.
Tested in Chrome (latest) and IE (10). Which browser are you using? Can you let me know which file and line number the error is referring to?
from github.
I did indeed, but spelled correctly I still get the TypeError. Working example: http://pomax.github.io/weblog, open the console, and run these:
var github = new Github({ username: "...", password: "..."});
var repo = github.getRepo("Pomax", "weblog");
repo.getTree("gh-pages");
(This branch definitely exists over at https://github.com/Pomax/weblog/tree/gh-pages)
With my credentials I get TypeError: Cannot call method 'encode' of undefined
, without a line number to tell me where the error is, so I'm also not sure where to look to find out what's actually causing it.
from github.
Looks like you forgot the callback function on that last line? Need something to receive the callback data.
Changing it to this it works:
repo.getTree("gh-pages", function(err, data) { console.log(data); });
from github.
That should then throw an "undefined is not a function" (or similar) error. In this case it's a TypeError where something is calling variable.encode()
without the variable actually being instantiated. I tried adding the callback, still get the TypeError. Does the Github constructor throw an error if the credentials don't work? I'm starting to wonder if that's the actual problem
from github.
Very strange. I also tried with a bad user/pass combo through the console on your webpage and get the same "TypeError: Cannot call method 'encode' of undefined"
as you, but works absolutely fine if it's done in the context of a webpage?
Tried with a token instead in the console with something like this and works fine, returns 6 objects as expected:
var github = new Github({token: "437867864892749737mytokenblahblah"});
var repo = github.getRepo("Pomax", "weblog");
repo.getTree("gh-pages", function(err, data) { console.log(data); });
Tokens are easy to set up and more secure. Maybe try with that?
Using a user/pass combo tho in the context of a console appears to not work tho and needs looking at.
from github.
Downside of a token is that it's harder to prompt users for so it doesn't need to be stored in the page's JS, but I guess if that's the only thing that seems to work, it'll have to do =)
(Using the token instead of the regular gh creds indeed works correctly)
from github.
That's a fair point - didn't know if this was just for you or not.
So, seems like a user/pass combo auth issue that only exists in the context of the console. Works fine if part of a webpage.
Exactly why that is I'm not sure, kind of an obscure bug but can look at this when I have 5 mins. :)
from github.
Marking as low priority bug for 0.10.7.
from github.
@mattpass Did you get anywhere with tracking that down?
from github.
@Aendrew No, only tracked down circumstances under which it could be reproduced.
from github.
note: pomax.github.io moved to a different git interface, so the demonstration links in previous comments are no longer valid.
from github.
I think this is closed now β I tried the sample code and tested it in the browser with Karma, can't reproduce.
If anyone comes across this again, please comment with a working test case and I'll reopen. Thanks!
from github.
I'm having the same issue as @Pomax.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/github-api/dist/github.min.js"></script>
<script src="js/main.js"></script>
</body>
</html>
main.js
var github = new Github({
username: "<username>",
password: "<password>",
auth: "basic"
});
var user = github.getUser();
user.orgs(function(err, orgs) {
console.log(orgs);
});
Here's a screenshot of the error in Chrome Version 48.0.2564.109 m (latest version).
from github.
same symptom but slightly different issue - I was using this purely server-side, because if you're putting in a username and password client-side you've just given the world your github login. Worth not doing.
from github.
If you don't want to use a module loading system, you have to use the dist/github.bundle.min.js
file.
from github.
Switching to dist/github.bundle.min.js
fixed my issue. Thanks @AurelioDeRosa π
from github.
just remember to never expose that username and password combination. Github's personal access tokens are a far safer authentication when using it client-side.
from github.
@Pomax Good idea! I would never even consider using username and password on a release version of an application, but since finding this library, I'm considering making a second account to use as a "bot" from which I can make Github API requests from a client browser (using token oauth of course)!
from github.
I kept things single account, but I have a small express server running on cheap shell host that only my sites can talk to (CORS/access whitelisting), which then does the talking to github for only the repos a site should be able to talk to. The client has a simple plain JS "same API but no authentication", and the server is essentially an authenticated proxy.
from github.
Related Issues (20)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from github.