首页 \ 问答 \ spring-boot我可以使用FacebookAuthenticationService连接apiKey和appSecret吗?(spring-boot can I use FacebookAuthenticationService to connect with apiKey and appSecret?)

spring-boot我可以使用FacebookAuthenticationService连接apiKey和appSecret吗?(spring-boot can I use FacebookAuthenticationService to connect with apiKey and appSecret?)

在基于spring-boot的应用程序中,我会让facebook用户朋友使用apiKey和appSecret来连接和facebook用户ID来识别用户(没有用户访问令牌)。

我知道通过facebook api graph我可以使用facebook api endpoint / {user-id} / friends获取用户好友列表,我可以使用app令牌代替用户访问令牌。

我试着像这样实现Facebook:

import org.springframework.social.facebook.api.Facebook;
import org.springframework.social.facebook.security.FacebookAuthenticationService;
...
Facebook facebook = new FacebookAuthenticationService(apiKey, appSecret);

但是当我在我的代码中包含这一行时,我得到了这个编译错误:

无法解析org.springframework.social.security.provider.OAuth2AuthenticationService类型。 它是从所需的.class文件间接引用的

在FacebookAuthenticationService.class里面有导入

import org.springframework.social.security.provider.OAuth2AuthenticationService;

在构建路径中不存在....我找不到

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-social-security</artifactId>

喜欢不是弹簧靴

<groupId>org.springframework.social</groupId>
<artifactId>spring-social-security</artifactId>

但我不能包括第二个'因为我会在实例化时得到一个不同的错误

        Facebook facebook = new FacebookAuthenticationService(apiKey, appSecret);

错误是:

类型不匹配:无法从FacebookAuthenticationService转换为Facebook

我想知道是否有人可以帮助我....


In a spring-boot based application, I would get facebook user friends using apiKey and appSecret to connect and facebook user Id to identify user (no user access token).

I know that via facebook api graph I can use facebook api endpoint /{user-id}/friends to get user friends list, and I can user the app token instead of user access token.

I'm tryng to instanciate Facebook like this:

import org.springframework.social.facebook.api.Facebook;
import org.springframework.social.facebook.security.FacebookAuthenticationService;
...
Facebook facebook = new FacebookAuthenticationService(apiKey, appSecret);

but when I include this line in my code I got this compile error:

The type org.springframework.social.security.provider.OAuth2AuthenticationService cannot be resolved. It is indirectly referenced from required .class files

inside FacebookAuthenticationService.class there is the import of

import org.springframework.social.security.provider.OAuth2AuthenticationService;

that doesn't exists in build path.... I can't find a

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-social-security</artifactId>

like the not spring-boot

<groupId>org.springframework.social</groupId>
<artifactId>spring-social-security</artifactId>

but I can't include the second one 'cause I will get a different error durind instantiation of

        Facebook facebook = new FacebookAuthenticationService(apiKey, appSecret);

the error is:

Type mismatch: cannot convert from FacebookAuthenticationService to Facebook

I'm wondering if someone can help me....


原文:https://stackoverflow.com/questions/35612334
更新时间:2022-04-23 18:04

最满意答案

这些行几乎是错误的(因为call_addone是用inlineCallbacks定义的):

    d = call_addone(4)
    d.callback(0)   # whatever I pass is set as deferred's result

随着这些行变得很奇怪(因为不使用inlineCallbacks ):

    d = addone(2)
    d.callback(0)   # whatever I pass is ignored

在这两种情况下,您都在要求一些库代码创建一个Deferred ,然后您的应用程序代码将为Deferred提供一个结果。 由于addone做你想做的事情,很明显可以使用Deferred这种方式。 但是,这不是一个好习惯。 最好的做法是负责创建解雇一个Deferred在同一个地方。 所以,在这种情况下,随着addone的实现。

你失败的测试失败的原因是你没有考虑到inlineCallbacks的实现,它认为它确实负责inlineCallbacks Deferred返回。 而Deferred它返回的不是由它所做的addone调用返回的Deferred 。 它保持了自我Deferred

d的结果在:

    d = call_addone(4)
    d.callback(0)   # whatever I pass is set as deferred's result

0原因正是因为您提供了0的结果。您已将结果提供给inlineCallbacks管理的Deferred并短路了inlineCallbacks所有其他实施。 如果由addone返回的Deferred确实触发过,那么您可能会看到AlreadyCalledError因为inlineCallbacks会尝试将结果提供给d ,而Deferred已经提供了结果。


These lines are pretty much wrong (given that call_addone is defined with inlineCallbacks):

    d = call_addone(4)
    d.callback(0)   # whatever I pass is set as deferred's result

This goes along with these lines being weird (given that inlineCallbacks is not used):

    d = addone(2)
    d.callback(0)   # whatever I pass is ignored

In both cases, you are asking some library code to create a Deferred and then your application code is supplying a result for the Deferred. Since addone does what you want, clearly it's possible to use Deferred this way. However, it's not a good practice. Best practice is for the responsibility for creating and firing a Deferred to lie in the same place. So, in this case, with the implementation of addone.

The reason your failing test fails is that you've not accounted for the implementation of inlineCallbacks which believes that it is indeed responsible for firing the Deferred it returns. And the Deferred it returns is not the Deferred returned by the addone call it makes. It keeps that Deferred to itself.

The result of d in:

    d = call_addone(4)
    d.callback(0)   # whatever I pass is set as deferred's result

is 0 precisely because you've supplied a result of 0. You've supplied the result to the inlineCallbacks-managed Deferred and short-circuited all of the rest of the implementation of inlineCallbacks. If the Deferred returned by addone did ever fire, you would likely see an AlreadyCalledError because inlineCallbacks would try to supply a result to d, the Deferred you already supplied a result to.

相关问答

更多
  • 在重新阅读有关Twisted Deferred回调和errbacks的文档后想出来。 上面代码和链接gist中的问题是回调和错误回复的缺失参数。 如果我用以下代码替换上面写的内容,则异常被捕获并通过errback按预期通知: def cb(result): pass def eb(failure): pass Figured it out after rereading the docs about Twisted Deferred callbacks and errbacks. The ...
  • Jonathan Lange写到了这个问题及其解决方案 。 您可能还需要考虑在单元测试中不使用真实的网络连接。 Agent已经有效了。 Site , reactor.listenSSL等也是如此。尝试编写运行代码的单元测试,而不是代码所依赖的库中的大量代码。 Jonathan Lange wrote about this problem and its solutions. You may also want to consider not using real network connections in ...
  • 你嘲笑time的方式确实有问题。 mock装饰器在输入测试函数时设置补丁,然后在退出时删除它们。 但是,您将返回Deferred ,这意味着time.time回调在测试函数退出后运行良好。 如果你只想继续使用类似于模拟的补丁界面,可以使用Twisted的TestCase.patch ,我相信这会考虑Deferreds 。 然而, 模拟是一种测试反模式 ,处理时间流逝的更好方法是使用记录的API来测试时间的流逝 , twisted.internet.task.Clock 。 There is indeed s ...
  • 我做的方式是创建假的响应,这样你可以离线测试解析函数。 但是您可以通过使用真正的HTML来获得真实的情况。 这种方法的一个问题是您的本地HTML文件可能无法反映在线的最新状态。 所以如果HTML在线改变你可能有一个很大的错误,但你的测试用例仍然会通过。 所以这可能不是最好的方式来测试这种方式。 我目前的工作流程是,每当发生错误时,我都会发送一封电子邮件给admin,并附上该URL。 那么对于那个具体的错误我创建一个html文件的内容导致错误。 然后我创建一个单元测试。 这是我用于从本地html文件创建样本S ...
  • 这些行几乎是错误的(因为call_addone是用inlineCallbacks定义的): d = call_addone(4) d.callback(0) # whatever I pass is set as deferred's result 随着这些行变得很奇怪(因为不使用inlineCallbacks ): d = addone(2) d.callback(0) # whatever I pass is ignored 在这两种情况下,您都在要求一些库代 ...
  • 您可以通过编写报告插件任意格式化试验输出。 你已经找到了该插件的界面 - IReporter 。 一旦你编写了这样一个插件,你就可以通过在trial命令行参数中添加--reporter=yourplugin来使用它。 您可以使用trial --help-reporters查看系统上已有的报告插件列表。 如果您安装了python-subunit那么您将看到subunit ,它是一种机器可解析的格式,可能已满足您的要求。 不幸的是,它仍然是一个亚单位v1记者,亚单位v2在很多方面都更好。 不过,它可能就足够了。 ...
  • 首先:你不能打电话给你的顶级单元测试包test 。 这是Python的单元测试的名称,因此您永远无法在已安装的配置中运行测试,并且根据您的python的设置方式,您可能最终导入python自己的测试而不是您自己的测试。 第二: sys.path是一个巨大而微妙的谜团。 trial支持在文件和目录上运行,作为快速入门的黑客攻击,但使用路径名永远不会完全正确。 正确的做法是传递一个模块 (或包)名称,它可以作为python模块导入并检查。 因此,如果您的目录结构如下所示: ~/Projects/MyProjec ...
  • Deferred类有大量的try / except魔法,以至于错误很好地从最终用户中提取出来,并且只能通过addErrback轻松获得。 如果发生错误,则表明您已经破坏了功能。 在同步应用程序中,您可以将“问题部分”封装在try / except块中。 在inlineCallbacks的情况下,可以使用相同的技术: try: run_test() except Exception as err: # handle error here finally: reactor.stop() ...
  • 用inlineCallbacks修饰的生成器函数返回Deferred - 而不是生成器。 情况总是如此。 您永远不能从使用inlineCallbacks修饰的函数返回生成器。 请参阅twisted.spread.util的寻呼机类,了解您可以采取的另一种方法。 A generator function decorated with inlineCallbacks returns a Deferred - not a generator. This is always the case. You can ne ...
  • 当然可以使用真正的Agent 。 您必须使用reactor作为第一个参数构造Agent实例; 因此,您可以提供假反应堆,例如MemoryReactor 。 虽然这是一个非常方便的方式来了解Agent正在做的事情,但它对于测试Agent本身来说确实非常有用。 注入一个假Agent很多次是一个更容易的路径,因为它的api都很浅(几乎所有东西都通过Agent.request和简单(它返回一个IResponse )) it is certainly possible to use a real Agent. You ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)