首页 \ 问答 \ 使用基于sign-post api的grails-oauth插件刷新Yahoo Oauth Access Token(Refresh Yahoo Oauth Access Token using grails-oauth plugin based on sign-post api)

使用基于sign-post api的grails-oauth插件刷新Yahoo Oauth Access Token(Refresh Yahoo Oauth Access Token using grails-oauth plugin based on sign-post api)

我正在使用grails oauth插件。 哪个成功地为我提供了yahoo的access_token 。 但问题是 - 这个令牌(来自雅虎)的有效期仅为1小时。 之后我们需要刷新它。 通过他们的文档,似乎他们有进程刷新它(如果令牌过期)。 此调用绕过第三条腿(用户的手动接受过程)。 这是非常好的!

现在,如果我尝试使用方法oauthService.fetchAccessToken - 我想这是命中get_access_token url(在提供者方)的方法。 但我得到例外:

oauth.signpost.exception.OAuthNotAuthorizedException:授权失败(服务器回复401)。 如果使用者密钥不正确或签名不匹配,则会发生这种情况。 at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:239)at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:189)at oauth.signpost.AbstractOAuthProvider.retrieveAccessToken(AbstractOAuthProvider.java:99)at oauth.signpost。 org.grails.plugins.oauth.OauthService.fetchAccessToken(OauthService.groovy:286)中的OAuthProvider $ retrieveAccessToken.call(未知来源)org.grails.plugins.oauth.OauthService $ fetchAccessToken.call(未知来源)


我已经进一步调试了插件和路标代码。 而且我认为我们应该研究路标(现在),插件可以在以后轻松修改。

为了您的信息,我使用signpost(jar - 1.2.1.1)与commonshttp4客户端

这是用于刷新accessToken的Yahoo文档页面的链接。 http://developer.yahoo.com/oauth/guide/oauth-refreshaccesstoken.html

雅虎在请求中需要oauth_session_handle参数,该参数由yahoo发送,带有accessToken。 Signpost确实提供了一种获取它的方法 - provider.getResponseParameters()

接下来是,我使用以下方法将这些参数放回到refreshToken请求中 - consumer.setAdditionalParameters(httpParams)

但它不起作用! 以下是stacktrace的一部分。 当我尝试获取refreshedAccessToken时

oauth.signpost.exception.OAuthNotAuthorizedException:授权失败(服务器回复401)。 如果使用者密钥不正确或签名不匹配,则会发生这种情况。 at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:239)at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:189)at oauth.signpost.AbstractOAuthProvider.retrieveAccessToken(AbstractOAuthProvider.java:99)

期待很快听到一些伟大/慷慨的家伙:-)

谢谢,萨利尔


I am using grails oauth plugin. Which is providing me yahoo's access_token successfully. But the problem is -- this token (from yahoo) has validity of 1 hr only. And after that we need to refresh it. And going through their documentation it seems like they have process to refresh it (in case token expires). And this call bypasses the thrid leg (user's manual acceptance process). that's very good!

Now, if I am trying to use method oauthService.fetchAccessToken -- I guess this is the method which hits get_access_token url (at provider's side). But I am getting exception:

oauth.signpost.exception.OAuthNotAuthorizedException: Authorization failed (server replied with a 401). This can happen if the consumer key was not correct or the signatures did not match. at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:239) at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:189) at oauth.signpost.AbstractOAuthProvider.retrieveAccessToken(AbstractOAuthProvider.java:99) at oauth.signpost.OAuthProvider$retrieveAccessToken.call(Unknown Source) at org.grails.plugins.oauth.OauthService.fetchAccessToken(OauthService.groovy:286) at org.grails.plugins.oauth.OauthService$fetchAccessToken.call(Unknown Source)


I have debugged further into plugin and signpost code. And I think we should look into signpost (for now), plugin can be modified easily later.

For your information, I am using signpost (jar - 1.2.1.1) with commonshttp4 client

here's the link of Yahoo documentation page for refreshing the accessToken. http://developer.yahoo.com/oauth/guide/oauth-refreshaccesstoken.html

Yahoo needs oauth_session_handle parameter in the request which is sent by yahoo with accessToken. Signpost does provides a way to fetch this -- provider.getResponseParameters().

Now next is, I am using following way to put these parameters back into the refreshToken request -- consumer.setAdditionalParameters(httpParams)

But it doesn't work! Following is the part of stacktrace. When I try to get the refreshedAccessToken

oauth.signpost.exception.OAuthNotAuthorizedException: Authorization failed (server replied with a 401). This can happen if the consumer key was not correct or the signatures did not match. at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:239) at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:189) at oauth.signpost.AbstractOAuthProvider.retrieveAccessToken(AbstractOAuthProvider.java:99)

looking forward to hear soon from some great/generous guy(s) :-)

Thanks, Salil


原文:https://stackoverflow.com/questions/7415279
更新时间:2022-08-26 07:08

最满意答案

您可以使用append=True set_index ,然后MultiIndex并保留MultiIndex

df.set_index(['id', 'type'], append=True).unstack()

在此处输入图像描述

或强行重新格式化您的要求:

# step-one same as above
df1 = df.set_index(['id', 'type'], append=True).unstack()
# collapse MultiIndex columns into '-' separated string
df1.columns = df1.columns.swaplevel(0, 1).to_series().str.join('-')
# move 'Id' from the index back into dataframe proper
df1 = df1.reset_index(1)
df1

在此处输入图像描述


You could set_index with append=True followed by unstack and keep the MultiIndex:

df.set_index(['id', 'type'], append=True).unstack()

enter image description here

Or forcibly reformat to what you asked for:

# step-one same as above
df1 = df.set_index(['id', 'type'], append=True).unstack()
# collapse MultiIndex columns into '-' separated string
df1.columns = df1.columns.swaplevel(0, 1).to_series().str.join('-')
# move 'Id' from the index back into dataframe proper
df1 = df1.reset_index(1)
df1

enter image description here

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用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)