对象#<facebook>没有方法'初始化'钛合金

时间:2015-10-07 04:48:15

标签: facebook titanium-mobile titanium-alloy titanium-modules titanium-android

我的Titanium应用程序有问题...我在互联网和Facebook模块上的Appcelerator上寻找了一些教程,更具体地说是登录/注销。我正试图在当天调整此错误,但我无论如何......如果您可以下载并测试会有帮助我提供下载项目!

我正在尝试登录到Android,但该应用程序也必须用于ios ...如果你能告诉我我是如何为我做两个或指示真正有效的项目....

下载我的项目:http://we.tl/hqvEpb2aeG

在我的文件下面:

Login.js

//Abir Fluxo de Caixa
function openFluxoDeCaixa(){
    var winFluxo = Alloy.createController('fluxo').getView();
    winFluxo.open();
}

fb.addEventListener('login', fbLogin);

$.btnLoginFacebook.addEventListener('click',function(e){
    fb.authorize();
});


function fbLogin(e){

    fb.removeEventListener('login', fbLogin);

    if(e.success){

        var fbdata = {};
        fbdata = JSON.parse(e.data);

        var uFoto = 'https://graph.facebook.com/' + fbdata.id + '/picture?width=300&height=300';
        var uNome = fbdata.name;

        var slipName = uNome.split(" ");

        Ti.App.Properties.setString('logged', 'true');
        Ti.App.Properties.setString('foto', uFoto);
        Ti.App.Properties.setString('nome', slipName[0]);

        openFluxoDeCaixa();
    } 
}


$.windowLogin.open();

Alloy.js

var fb = require('facebook');
fb.permissions = ['public_profile', 'read_stream'];
fb.appid = 172237596444060;
fb.forceDialogAuth = false;
fb.initialize();

if(OS_ANDROID){
    $.windowLogin.fbProxy = fb.createActivityWorker({lifecycleContainer: $.windowLogin});
}



Alloy.Globals.LocalFunctions = {
    setLogin : function setLogin(uId, uNome, uPlataforma){

    var getLogin = Titanium.Network.createHTTPClient();
        getLogin.open("POST","http://www.skrow.cc/ws-qia/controller.php");

        var params = {
            action: 'addLogin',
            id: uId,
            nome: uNome,
            plataforma: uPlataforma
        };

        getLogin.send(params);
    }
};

TiApp.xml

<?xml version="1.0" encoding="UTF-8"?>
<ti:app xmlns:ti="http://ti.appcelerator.org">
    <id>br.com.queroinvestiragora</id>
    <name>Quero Investir Agora</name>
    <version>1.0</version>
    <publisher>silviosampaio</publisher>
    <url>http://www.queroinvestiragora.com.br</url>
    <description>undefined</description>
    <copyright>2015 by silviosampaio</copyright>
    <icon>appicon.png</icon>
    <fullscreen>false</fullscreen>
    <navbar-hidden>false</navbar-hidden>
    <analytics>true</analytics>
    <guid>284edc0c-c599-4cae-9444-721cd3d22937</guid>
    <property name="ti.ui.defaultunit" type="string">dp</property>
    <ios>
        <plist>
            <dict>
                <key>UISupportedInterfaceOrientations~iphone</key>
                <array>
                    <string>UIInterfaceOrientationPortrait</string>
                </array>
                <key>UISupportedInterfaceOrientations~ipad</key>
                <array>
                    <string>UIInterfaceOrientationPortrait</string>
                    <string>UIInterfaceOrientationPortraitUpsideDown</string>
                    <string>UIInterfaceOrientationLandscapeLeft</string>
                    <string>UIInterfaceOrientationLandscapeRight</string>
                </array>
                <key>UIRequiresPersistentWiFi</key>
                <false/>
                <key>UIPrerenderedIcon</key>
                <false/>
                <key>UIStatusBarHidden</key>
                <false/>
                <key>UIStatusBarStyle</key>
                <string>UIStatusBarStyleDefault</string>
                <key>CFBundleURLTypes</key>
                <array>
                    <dict>
                        <key>CFBundleURLName</key>
                        <string>com.appcelerator.kitchensink</string>
                        <key>CFBundleURLSchemes</key>
                        <array>
                            <string>kitchensink</string>
                            <string>936940282991759</string>
                        </array>
                    </dict>
                </array>
            </dict>
        </plist>
    </ios>
    <android xmlns:android="http://schemas.android.com/apk/res/android">
        <manifest>
            <application android:theme="@style/Theme.NoActionBar">
                <activity android:label="@string/app_name"
                    android:name="com.facebook.LoginActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
                <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
            </application>
        </manifest>
    </android>
    <mobileweb>
        <precache/>
        <splash>
            <enabled>true</enabled>
            <inline-css-images>true</inline-css-images>
        </splash>
        <theme>default</theme>
    </mobileweb>
    <modules>
        <module platform="commonjs">ti.cloud</module>
        <module platform="android" version="3.0.3">facebook</module>
        <module platform="iphone" version="3.2.0">facebook</module>
    </modules>
    <deployment-targets>
        <target device="android">true</target>
        <target device="blackberry">false</target>
        <target device="ipad">false</target>
        <target device="iphone">true</target>
        <target device="mobileweb">false</target>
    </deployment-targets>
    <sdk-version>3.5.1.GA</sdk-version>
    <plugins>
        <plugin version="1.0">ti.alloy</plugin>
    </plugins>
    <property name="appc-app-id" type="string">55ec85b523ec2d9730087189</property>
    <property name="acs-authbase-url-development" type="string">https://secure-identity.cloud.appcelerator.com</property>
    <property name="acs-base-url-development" type="string">https://api.cloud.appcelerator.com</property>
    <property name="acs-oauth-secret-development" type="string">0VlBf7xO3Z3aWr2ISM6BXr2vxQH8OPaU</property>
    <property name="acs-oauth-key-development" type="string">T8j8E5AOcEyUGOPtSZWaA4ygJLpi0pYL</property>
    <property name="acs-api-key-development" type="string">5p3UAhCmk7I3H9lYzip5Wb97H0h9I38V</property>
    <property name="acs-username-development" type="string">appc_app_user_dev</property>
    <property name="acs-password-development" type="string">fUoxkjYTGqxoE8ZTJ0</property>
    <property name="acs-authbase-url-production" type="string">https://secure-identity.cloud.appcelerator.com</property>
    <property name="acs-base-url-production" type="string">https://api.cloud.appcelerator.com</property>
    <property name="acs-oauth-secret-production" type="string">2JHJ4oZ4V0Ch5Gvy3GAnEkY4stnycUYn</property>
    <property name="acs-oauth-key-production" type="string">UTUK7lzz2Vuq54fSAErTk4NaN3kghPOJ</property>
    <property name="acs-api-key-production" type="string">3xGYGFJQAYXBK4quHslbKCfBtgAcCgXg</property>
    <property name="acs-username-production" type="string">appc_app_user</property>
    <property name="acs-password-production" type="string">rDD4YG0qQxtmdXg0yM</property>
    <property name="appc-org-id" type="string">100026191</property>
    <property name="appc-creator-user-id" type="string">baea2ab2-d377-4f02-aa1b-6b4553ffe12d</property>
</ti:app>

1 个答案:

答案 0 :(得分:1)

Alloy.js总是在您的应用启动时执行,但默认情况下,您在其中创建的变量无法从其他控制器访问。

您需要在全局范围内访问您的facebook模块才能在alloy.js之外访问它,您可以通过更改alloy.js中的以下行来完成此操作:

var fb = require('facebook');
fb.permissions = ['public_profile', 'read_stream'];
fb.appid = 172237596444060;
fb.forceDialogAuth = false;
fb.initialize();

Alloy.Globals.fb = require('facebook');
Alloy.Globals.fb.permissions = ['public_profile', 'read_stream'];
Alloy.Globals.fb.appid = 172237596444060;
Alloy.Globals.fb.forceDialogAuth = false;

在login.js中,您还需要在调用fb.initialize()之前设置成功登录facebook的回调函数,例如:

Alloy.Globals.fb.addEventListener('login', fbLogin);

此外,您必须在尝试调用fb.initialize()或fb.authorize()之前设置登录/注销函数,这样您才需要将fb.initialize()移动到login.js或者只是从alloy.js中删除它,因为你已经调用了fb.authorize()。