- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们有一个适用于 Android 的 Cordova/PhoneGap 应用程序,用户可以使用 PhoneGap Facebook Connect 插件 ( https://github.com/Wizcorp/phonegap-facebook-plugin ) 使用他们的 Facebook 帐户登录。
但是,每次用户在设置中更改国家/地区时,我们都需要使用新的 AppId/AppName 以编程方式更新 Facebook session ,因为我们为每个国家/地区提供不同的 Facebook 应用程序。
我们可以创建一个连接到 Phonegap Facebook Connect 插件的自定义插件,每当用户更改国家或尝试使用 Facebook 登录时调用该插件:
package com.OURAPP.facebook;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaArgs;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.json.JSONException;
import android.app.Activity;
import com.facebook.Session;
public class FacebookConnectMultiPlugin extends CordovaPlugin {
private Activity context;
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
context = cordova.getActivity();
}
@Override
public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException {
if (action.equals("changeAppId")) {
String appId = args.getString(0);
Session session = new Session.Builder(context).setApplicationId(appId).build();
Session.setActiveSession(session);
callbackContext.success();
return true;
} else {
return false;
}
}
}
然而,在将 Phonegap Facebook Connect 更新到最新版本后(现在它使用新的 Facebook SDK),我们的自定义插件停止工作,我们无法找出问题所在。
如果它有帮助,我们在 iOS 上遇到了同样的问题,但我们可以解决它。在那种情况下,我们没有更新 Facebook AppName,但是,我们找不到在 Android 上执行此操作的任何方法。
这是我们的旧代码:
#import "FacebookConnectMultiPlugin.h"
#import <FacebookSDK/FacebookSDK.h>
@interface FacebookConnectMultiPlugin ()
@property (strong, nonatomic) NSString *appid;
@end
@implementation FacebookConnectMultiPlugin
- (void)changeAppId:(CDVInvokedUrlCommand*)command
{
CDVPluginResult* pluginResult = nil;
NSString* myarg = [command.arguments objectAtIndex:0];
NSLog(@"This is the app id: %@", myarg);
FBSession *session = [[FBSession alloc] initWithAppID:myarg
permissions:nil
defaultAudience:FBSessionDefaultAudienceFriends
urlSchemeSuffix:nil
tokenCacheStrategy:nil];
[FBSession setActiveSession:session];
if (myarg != nil) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Arg was null"];
}
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
@end
这是新代码:
#import "FacebookConnectMultiPlugin.h"
#import <FacebookSDK/FacebookSDK.h>
@interface FacebookConnectMultiPlugin ()
@property (strong, nonatomic) NSString *appid;
@end
@implementation FacebookConnectMultiPlugin
- (void)changeAppId:(CDVInvokedUrlCommand*)command
{
CDVPluginResult* pluginResult = nil;
NSString* myarg = [command.arguments objectAtIndex:0];
NSString* myDisplayName = [command.arguments objectAtIndex:1];
NSLog(@"----------------------");
NSLog(@"This is the app id: %@", myarg);
NSLog(@"This is the display name: %@", myDisplayName);
NSLog(@"----------------------");
FBSession *session = [[FBSession alloc] initWithAppID:myarg
permissions:nil
defaultAudience:FBSessionDefaultAudienceFriends
urlSchemeSuffix:nil
tokenCacheStrategy:nil];
[FBSession setActiveSession:session];
[FBSettings setDefaultAppID:myarg];
[FBSettings setDefaultDisplayName:myDisplayName];
if (myarg != nil) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Arg was null"];
}
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
@end
最佳答案
如果您有不同的 Facebook 应用程序,用户需要切换到该应用程序,那么他们也需要授权该应用程序。如果他们已经登录,您需要通过调用 Session.getActiveSession().closeAndClearTokenInformation()
将他们注销。
然后您可以像使用 Session.Builder 一样构建 session ,但是您必须使用 OpenRequest 打开它。查看 session.openForRead 是如何调用的 here .
此外,您还必须使用 UiLifecycleHelper 并实现 onActivityResult,您可以在此 post 中查看更详细的解释.
关于android - 在 Android 上使用新的 AppID 更新 Facebook SDK session (使用 Cordova/PhoneGap),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28515011/
当我打开 FBSession (FB SDK 3.0) 时,出现此错误: FBSession: No AppID provided; either pass an AppID to init, or
我正在关注此链接(Link),以显示Kibana上的实时天气数据。我正在使用logstash将实时数据存储到elasticsearch。 我使用了pdf中解释的logstash配置。 这是我的logs
我陷入了一个有点奇怪的境地。当我们的应用程序首次创建时,没有人真正知道他们在做什么,我正在尝试清理一下。 在iOS开发者中心,我的应用好像有两个App ID。我想我可以删除其中一个,因为另一个是实际正
我想在 Swift 中使用 facebook 登录。他们给我错误 AppId not set in Plist 但我在 plist 上设置 AppId。它给出了这个错误: my2015-08-12 1
如何在 Azure Bot 服务中提供 AppId。今后所有 Microsoft 机器人框架应用程序都将位于 Azure 机器人服务中。在 Microsoft bot 框架的开发门户中,我们可以在创建
我正在尝试在我的网站中添加和配置 react-facebook(评论),但是关于 react facebook 的资源不多,所以我很感兴趣 我应该添加什么来代替“123456789”(
例如,我修改了用于窃听 FB API 的样板代码,以符合 jslint。它看起来像这样: (function () { 'use strict'; window.fbAsyncInit
我正在尝试使用适用于 Python 的 Bing Translator API,但出于某种原因,它告诉我我的 AppID 无效。我收到错误: ArgumentException: Invalid ap
我在 iOS 中使用 PayPal MPL,因为我需要链式和并行付款(在卖家和我之间分摊费用)。似乎我找不到 PayPal AppID 所在的位置以在应用程序委托(delegate)中完成此操作: [
我创建了 Crittercism 帐户并关注了 this集成到我的 Android 应用程序中,但无法获取应用程序 ID。 任何人请帮助我从 Crittercism 帐户获取应用程序 ID。 TIA
我最近接手了一个iPhone项目,之前从来没有用过objective-c。 我必须让应用程序使用推送通知,但第一个 appId 已经生效并使用通配符(因此没有推送通知)。 我创建了另一个带有标识符的
我正在尝试了解 AppID 的第一部分对 iOS 应用程序的作用。这部分以前称为“Bundle Seed ID”,但现在通常称为 AppID Prefix。 不久前(iOS 5?),Apple 在其门
我试图理解这里的应用 ID 和配置文件,但我完全迷失了。 我是一名全名注册的 Apple 开发者,目前我有 2 个应用程序正在开发中,并且有 2 个设备 UDID 可供测试。 我希望能够为这两个应用程
我正在尝试将 ClaimMappingPolicy 与图形 API 中的主要服务关联起来: 我尝试使用对象id和appid进行调用,但它不起作用,找不到资源,但资源退出: 并且该政策也存在: 为什么不
也许这是个很愚蠢的问题,但我真的迷路了。 文档描述的一切都很简单:http://admin.wechat.com/wiki/index.php?title=Startup#AppId_and_AppS
我计划将 Facebook 共享添加到我的网站中,并且我需要以下信息来共享我的内容: // Facebook information export const FACEBOOK = { "appId"
我们的 Android 应用程序将由另一家公司接管。这需要更改 app-id/package-id(从 com.mycompany.app 到 com.newcompany.app)。但是,当安装更新
我正在修改自适应支付的 woocommerce paypal 标准。请让我知道如何通过标准支付html模式传递paypal AppID。 谢谢 https://wordpress.org/plugin
我使用 ASP.NET 网络表单创建了一个 SharePoint 提供商托管应用程序。我正在尝试访问安装了该应用程序的 SharePoint 网站中的列表。当我尝试获取 clientContext 时
我是 PushNotifications 的新手。我在为现有 AppID 启用推送通知时遇到了问题。 很久以前,我为一个应用程序创建了证书,配置文件。当时我没有启用推送通知。为了启用推送通知,我登录了
我是一名优秀的程序员,十分优秀!