oauth-io / oauth-phonegap

OAuth.io plugin for Apache Cordova/PhoneGap
195 stars 69 forks source link

OAuth is not defined #24

Closed tuimz closed 10 years ago

tuimz commented 10 years ago

Hi,

I am having an error where OAuth seems to be undefined.

Steps to reproduce:

phonegap create testApp
phonegap plugin add https://github.com/oauth-io/oauth-phonegap

This step says the plugin is installed successfully. However:

phonegap plugin list
[phonegap] no plugins installed

I might be missing some steps? 3.5.0-0.20.4 is my phonegap version

william26 commented 10 years ago

Hello,

We also encountered the problem with the empty plugin list. This seems to be an issue with Phonegap 3.5.0-0.20.4.

There is a commit on the Phonegap repository fixing it (see their Issue 348) but I don't think it's been released yet. For now, rolling back to Phonegap 3.4.x seems to fix the problem.

Hope this helps :)

tuimz commented 10 years ago

Even when using

phonegap 3.4.0-0.20.0

I still get the error:

OAuth is not defined

When I use the phonegap plugin list command it does show in the installed plugins. Do I need to edit the www/config.xml?

william26 commented 10 years ago

Indeed you need to change the <access origin="..." /> tag in the www/config.xml file to access https://oauth.io and the url of the API you want to use. While developing, you can set it like this:

<!-- ... -->
<access origin="*" />
<!-- ... -->

I went through the following steps on an android device with 3.4.0-0.20.0 and everything seems to work normally.

$ phonegap create myProject
$ cd myProject
$ phonegap plugin add https://github.com/oauth-io/oauth-phonegap

I added the weinre script at the end of the index.html file (checkout their website for more info).

 <access origin="*"/>
$ phonegap run android
> OAuth.initialize('my key');
> OAuth.popup('facebook').done(function (r) { window.r = r }).fail(function (e) { console.log(e) })
> r.me().done(function (me) { console.log(me) } ).fail(function (e) { console.log(e) })

I hope that will solve your problem :) Please tell us if something still doesn't work.

tuimz commented 10 years ago

Is there no way of testing the application without deploying it to a phone. e.g with phonegap serve or the Ripple Emulator chrome plugin?

william26 commented 10 years ago

A good way to test the application outside of deploying it on a device would be running it on device simulators.

If you have the Android SDK installed, start an emulator from the Android Virtual Device Manager, and run the same command from console:

$ phonegap run android

If you are on mac and have Xcode installed, you can also test your app on the iOS simulator. Launch the simulator, and run:

$ phonegap run ios

You can force the command to run on the emulator by adding the argument --emulator.

You can use weinre to access the page and have a console similar to Google Chrome's console. All you need to do is run the weinre server, include the weinre script tag on your index.html file, and access http://localhost:8080 on your browser.

Hope this helps :)

tuimz commented 10 years ago

Seems to be working. I was under the assumption that it would work with the phonegap serve command too. But it doesn't yet, might be in the near future though: https://github.com/phonegap/phonegap-cli/issues/315