GithubHelp home page GithubHelp logo

Comments (19)

mattpass avatar mattpass commented on August 21, 2024

@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.

Pomax avatar Pomax commented on August 21, 2024

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.

mattpass avatar mattpass commented on August 21, 2024

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.

Pomax avatar Pomax commented on August 21, 2024

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.

mattpass avatar mattpass commented on August 21, 2024

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.

Pomax avatar Pomax commented on August 21, 2024

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.

mattpass avatar mattpass commented on August 21, 2024

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.

aendra-rininsland avatar aendra-rininsland commented on August 21, 2024

Marking as low priority bug for 0.10.7.

from github.

aendra-rininsland avatar aendra-rininsland commented on August 21, 2024

@mattpass Did you get anywhere with tracking that down?

from github.

mattpass avatar mattpass commented on August 21, 2024

@Aendrew No, only tracked down circumstances under which it could be reproduced.

from github.

Pomax avatar Pomax commented on August 21, 2024

note: pomax.github.io moved to a different git interface, so the demonstration links in previous comments are no longer valid.

from github.

aendra-rininsland avatar aendra-rininsland commented on August 21, 2024

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.

davidcorbin avatar davidcorbin commented on August 21, 2024

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).
2016-02-15 16_46_27-settings

from github.

Pomax avatar Pomax commented on August 21, 2024

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.

AurelioDeRosa avatar AurelioDeRosa commented on August 21, 2024

If you don't want to use a module loading system, you have to use the dist/github.bundle.min.js file.

from github.

davidcorbin avatar davidcorbin commented on August 21, 2024

Switching to dist/github.bundle.min.js fixed my issue. Thanks @AurelioDeRosa πŸ˜„

from github.

Pomax avatar Pomax commented on August 21, 2024

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.

davidcorbin avatar davidcorbin commented on August 21, 2024

@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.

Pomax avatar Pomax commented on August 21, 2024

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.