2017-02-02 47 views
0

我試圖在撥打https://facebook.com/v2.8/dialog/oauth後讓Facebook重定向回我的Unity應用程序(在android上運行)。我在我的android應用程序中創建了一個自定義URL方案,如myApp://。但是,當我嘗試通過Facebook發送OAuth請求時,它告訴我redirect_uri不受支持。我試圖將我的自定義網址添加到我的Facebook應用的OAuth設置中,但它表示它不是有效的網址(這很合理,因爲它在技術上不是)。Facebook OAuth重定向和自定義應用程序URL Scehem

請求:

var url = string.Format("https://facebook.com/v2.8/dialog/oauth?client_id={0}&response_type=token&redirect_uri={1}", "MYAPPID", "redfish%3A%2F%2Ffacebooklogin");

我的應用程序的AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> 
    <application android:icon="@drawable/app_icon" android:label="@string/app_name"> 
    <activity android:name=".MainActivity" android:label="@string/app_name" android:launchMode="singleTask" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="sensor"> 
     <intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 
     <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
     <intent-filter> 
     <data android:scheme="redfish" /> 
     <action android:name="android.intent.action.VIEW" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
     <category android:name="android.intent.category.BROWSABLE" /> 
     </intent-filter> 
    </activity> 
    </application> 
</manifest> 

代碼團結捕捉重定向:使用

public class OnAcessToken : MonoBehaviour { 

    void OnAccessToken(string accessToken) 
    { 
     Debug.Log("Received access token: " + accessToken); 
     SceneManager.LoadScene("FileSelect"); 
    } 
} 

OnAccessToken被擊中由指令生成的自定義庫離子在http://oferei.com/2013/06/serverless-instagram-authentication/

我在問的是如何讓Facebook允許我的自定義URL方案作爲有效的redirect_uri?或者我正在以這種錯誤的方式去做。

回答

1

結束了一些額外的研究回答我自己的問題。對於android使用自定義URL架構不是必要的,據Google稱,使用類似myApp://之類的做法已被棄用。

相反,我的模式現在是http://myApp.auth,以及相應的意圖過濾器看起來是這樣的:現在

<intent-filter> 
     <data android:scheme="http" 
       android:host="redfish.auth/> 
     <action android:name="android.intent.action.VIEW" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
     <category android:name="android.intent.category.BROWSABLE" /> 
</intent-filter> 

,在Facebook的設置,我可以設置http://redfish.auth一個可以接受的OAuth的URL,它不會抱怨因爲它具有http架構。這覆蓋了主機而不是模式,所以它在Chromium瀏覽器中工作(以前不是因爲前面提到的Chrome標準)。

因此,當我打電話給http://redfish.auth/facebooklogin時,它會重定向回我的應用程序!

參考文獻:https://developer.android.com/guide/components/intents-filters.html

+0

我喜歡你的解決方案,但因爲我在手機上測試了三星的默認網絡瀏覽器的應用程序,而不是瀏覽器不工作對我來說,也許?瀏覽器將http://myapp.auth解釋爲網址,並返回'myapp.auth的DNS地址找不到'。儘管已將http作爲方案放置在清單文件中的intent過濾器中。所以無論這種方法只適用於某些瀏覽器或我做錯了什麼 – anything