- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想在 android 中集成 foursquare。所以我尝试了两个例子。
第一个例子:
public class ActivityWebView extends Activity
{
private static final String TAG = "ActivityWebView";
/**
* Get these values after registering your oauth app at: https://foursquare.com/oauth/
*/
public static final String CLIENT_ID = "";
public static final String OAUTH_CALLBACK_SCHEME = "x-oauthflow-foursquare";
public static final String OAUTH_CALLBACK_HOST = "callback";
public static final String CALLBACK_URL = OAUTH_CALLBACK_SCHEME + "://" + OAUTH_CALLBACK_HOST;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
String url =
"https://foursquare.com/oauth2/authenticate" +
"?client_id=" + CLIENT_ID +
"&response_type=token" +
"&redirect_uri=" + CALLBACK_URL;
// If authentication works, we'll get redirected to a url with a pattern like:
//
// http://YOUR_REGISTERED_REDIRECT_URI/#access_token=ACCESS_TOKEN
//
// We can override onPageStarted() in the web client and grab the token out.
WebView webview = (WebView)findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
public void onPageStarted(WebView view, String url, Bitmap favicon) {
String fragment = "#access_token=";
int start = url.indexOf(fragment);
if (start > -1) {
// You can use the accessToken for api calls now.
String accessToken = url.substring(start + fragment.length(), url.length());
Log.v(TAG, "OAuth complete, token: [" + accessToken + "].");
Toast.makeText(ActivityWebView.this, "Token: " + accessToken, Toast.LENGTH_SHORT).show();
}
}
});
webview.loadUrl(url);
}
第二个例子:
http://blog.doityourselfandroid.com/2011/09/05/integrate-foursquare-android-application/
我在 list 文件中添加了额外的代码
<activity android:name=".ActivityWebView" android:launchMode="singleTask" android:noHistory="true">
<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:scheme="x-oauthflow-foursquare" android:host="callback" />
</intent-filter>
</activity>
运行两个应用程序后,身份验证成功,但它显示带有此消息的 Web View
you dont have permission to open this page x-oauthflow-foursquare://callback#access_token=DRWDP004zzAIZ1PPJEANEBFCM3NZJ1T414U2Z
所以请告诉我它是否需要添加任何额外的权限。请解决我的问题。
最佳答案
使用 Foursquare API 检查此代码的身份验证部分和回调部分:
public class ActivityMain extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button)findViewById(R.id.button);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(ActivityMain.this, ActivityWebView.class);
startActivity(intent);
}
});
}
}
ActivityWebView.Java:点击按钮后:
public class ActivityWebView extends Activity{
private static final String TAG = "ActivityWebView";
public static final String CLIENT_ID = "01QWBUR2UUFSMMLZXOM5YY0UWCM4BC0F2IOZDJ0S5XGOINQM";
public static final String OAUTH_CALLBACK_SCHEME = "x-oauthflow-foursquare";
public static final String OAUTH_CALLBACK_HOST = "callback";
public static final String CALLBACK_URL = OAUTH_CALLBACK_SCHEME + "://" + OAUTH_CALLBACK_HOST;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
String url =
"https://foursquare.com/oauth2/authenticate" +
"?client_id=" + CLIENT_ID +
"&response_type=token" +
"&redirect_uri=" + CALLBACK_URL;
WebView webview = (WebView)findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
public void onPageStarted(WebView view, String url, Bitmap favicon) {
String fragment = "#access_token=";
int start = url.indexOf(fragment);
if (start > -1) {
// You can use the accessToken for api calls now.
String accessToken = url.substring(start + fragment.length(), url.length());
Log.v(TAG, "OAuth complete, token: [" + accessToken + "].");
Toast.makeText(ActivityWebView.this, "Token: " + accessToken, Toast.LENGTH_SHORT).show();
editor.putString("Access_Token", accessToken);
editor.commit();
startActivity(new Intent(ActivityWebView.this,Nearest_Places_View.class)); // After Successfull Login the Web view will Redirected to Nearest_Places_View Activity
}
}
});
webview.loadUrl(url);
}
}
activity_webview.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
回调后的 Activity :
public class Nearest_Places_View extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.anylayout);
// Do your All stuff for Foursquare for example getting User Checkins,Nearest Place
}
}
您的 list 文件应如下所示:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.foursquare.android.oauth"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ActivityMain" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Nearest_Places_View"
/>
<activity android:name=".ActivityWebView" android:launchMode="singleTask">>
<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:scheme="x-oauthflow-foursquare" android:host="callback" />
</intent-filter>
</activity>
所有三个回调应该相同 1. Activity 2.manifest 3.Settings Page。那么只有它会起作用。
关于android - android 中的 foursquare 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7845361/
我查看了 Foursquare API 文档,但我找不到让 Foursquare 告诉我用户通过特定 checkin 获得多少积分的方法。 最佳答案 checkin 响应有一个字段 score文档中(
我正在开发一款允许用户搜索 Foursquare 的 iPhone 应用程序。我正在使用 venues/explore 端点进行搜索,效果很好,但结果不包括地点或 priceTier 的图像。 现在我
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
可以在网站上添加 Foursquare 签到功能吗? 最佳答案 虽然您可以在网站上提供签到功能,但请谨慎使用并意识到可能难以遵守适当的 Foursquare API 要求。 (张贴者 amelvin
我已经浏览了foursquare api,但找不到我想要的。 我需要获取所有地名、城市名称、国家/地区名称以及经度和纬度。 有具体的 api url 吗? 提前致谢。 最佳答案 如果您可以构建一个好的
我已经查看了 foursquare api,但是找不到我想要的。 我需要获取所有地名、城市名、国家名和经纬度。 是否有任何特定的 api url? 提前致谢。 最佳答案 如果您可以构建一个好的守护进程
提前感谢您的宝贵时间。 我想知道如何通过传递 Foursquare 类别 ID 以编程方式获取 Foursquare 类别的相应图像。 p> 我已经阅读了 API 文档,但到目前为止还没有找到解决方案
我正在尝试获得对 specific restaurant 的评论使用 Foursquare API,但我没有得到与 Foursquare 网站上相同的(所有)结果。 我使用了 Foursquare A
这是我的链接,它提供了 foursuqare field 的结果,但是当我应用从 0 到 2 等的偏移量时,它在每次运行中都为我提供了相同的结果。 https://api.foursquare.com
Foursquare API v2 不支持消费者的多个回调 URL 有什么原因吗?必须为每个测试环境定义一个全新的应用程序,这对开发运营来说是一个很大的障碍。据我所知,没有其他主要网络将应用重定向限制
有谁知道是否可以从移动网页启动 iPhone 或 Android Foursquare 应用程序?我们可以使用自定义 URL 方案吗? 如果用户安装了应用程序而不是网站,我们的客户希望为用户提供使用该
新的 field url 更漂亮,但 ID 不存在,并且没有机制从漂亮的 url 中查找 ID。 例如,这个特定的 url: https://foursquare.com/felice_83 如何查询
包含 categoryId 参数时,我从 API 查询中获得了意外结果。 例如,当使用以下参数在马萨诸塞州波士顿搜索“The Citizen Public House”时 ll: 42.3489027
我正在开发一个应用程序,它通过 Foursquare 的原生 oauth for Android 库连接到 Foursquare。我已经实现了 Foursquare 在其 github 个人资料中建议
在 Foursquare API Explorer 窗口中,我们使用端点“venues/search?ll=39.8647,-86.2604&intent=browse&radius=20000&li
我从 Foursquare API 开始,在 Python ,而且我不确定为什么我无法进行身份验证。 按照教程,到目前为止,我有这段代码: import foursquare client = fou
我正在调用 Foursquare Venue API 来获取伦敦的所有美食场所。 使用的API是:https://api.foursquare.com/v2/venues/explore?ll=51.
今天早上,我看到 Foursquare 将其单一服务拆分为 2 个 - 一个称为 Swarm,另一个保留 Foursquare 名称。我查看了 Foursquare 开发者博客,但(目前)还没有看到任
这对我来说没有多大意义,我希望有人可以对这里发生的事情以及我如何解决它有所了解。 如果我这样查询: https://api.foursquare.com/v2/venues/search?ll=37.
是否可以以贪婪的方式从foursquare抓取签到数据? (即使我与所有用户都没有友谊)就像抓取公开可用的 twitter 消息一样。如果您有任何经验或建议,请分享。谢谢。 最佳答案 如果您有包含指向
我是一名优秀的程序员,十分优秀!