【问题标题】:OAuth2 CallBack Google Custom TabsOAuth2 回调 Google 自定义标签
【发布时间】:2018-03-20 05:57:29
【问题描述】:

我正在开发一个使用 FitBit API 检索用户数据的 Android 应用程序。然后在应用程序中进一步使用它们。为了完成这项工作,使用 OAuth2 进行授权。第一步是征得用户同意在特定范围内使用数据。

为了完成这项工作,我使用 FitBit 规定的 Google 自定义标签。该网址在网络浏览器中有效,当我在 Android 设备上对其进行测试时,它也有效,将我定向到用户同意页面。当我点击“同意”按钮时,我不会被重定向到应用程序。相反,我最终进入了带有授权码的 callback_url 页面。但我仍然没有通过“System.in.println()”得到任何回报。如何使用 SYSTEM.IN 中的授权代码返回我的应用程序?

以下是我最终到达的页面..

我将重定向 URL 用于开发目的,“http://locallhost.com/”,以允许我在开发中进行测试。这在清单中设置为意图过滤器(见下文),即我的应用程序在 Fitbit API 端点的应用程序设置。

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

final CustomTabsIntent intent = new CustomTabsIntent.Builder().build();
    final String url = "https://www.fitbit.com/oauth2/authorize/myApplicationParameters";
    intent.launchUrl(this, Uri.parse(url));

System.out.println(in.hasNextLine());

清单

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

【问题讨论】:

标签: android chrome-custom-tabs


【解决方案1】:

我最终使用了 callback_uri "niels://fitbitcallback"。使用 http:// 或 https:// 让 Android Studio 感到困惑。这对我不起作用。最重要的是,我使用了一个额外的活动来将用户重定向到。还相应地调整了 Android Manifest。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-22
    • 2017-04-29
    • 1970-01-01
    • 1970-01-01
    • 2017-06-12
    相关资源
    最近更新 更多