使用基于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 hitsget_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
最满意答案
您可以使用
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
withappend=True
followed byunstack
and keep theMultiIndex
:df.set_index(['id', 'type'], append=True).unstack()
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
相关问答
更多-
Pandas数据框到AnguarJS(Pandas dataframe to AnguarJS)[2019-10-11]
pandas.DataFrame.to_json()然后在AngluarJS中渲染会不会更容易? 感觉就像html步骤增加了复杂性。 It worked without changing anything. Saved the dataframe to textfiled() after .to_html, serialized it with drf and used ng-sanitize in AngularJS and the tables rendered. -
你可以使用pd.crosstab : import numpy as np import pandas as pd df = pd.read_table('data', sep='\s{2,}', parse_dates=[0]) table = pd.crosstab(index=[df['timestamp']], columns=[df['colA'], df['colB']]) 产量 colA a b colB x ...
-
默认的agg函数是np.mean (即使你没有明确地传递它,这是正在使用的东西),这对字符串没有意义,实际上它在传递一个对象数组时引发了一个AttributeError - 所以pandas抱怨当你试图这样做。 你可以传递np.sum : In [11]: pd.pivot_table(df2, rows=['ID', 'Count'], cols='Value_type', values='Value', aggfunc=np.sum) Out[11]: ...
-
将pandas数据帧转换为前缀cols,而不是MultiIndex(pivoting pandas dataframe into prefixed cols, not a MultiIndex)[2022-05-09]
我想到了。 使用MultiIndex上的数据可以提供非常干净的解决方案: def flatten_multi_index(df): mi = df.columns suffixes, prefixes = mi.levels col_names = [prefixes[i_p] + '_' + suffixes[i_s] for (i_s, i_p) in zip(*mi.labels)] df.columns = col_names return df flatt ... -
import pandas as pd import numpy as np # just try to replicate your dataframe # ============================================== date = ['2015-07-08', '2015-07-07', '2015-07-07', '2015-07-07', '2015-07-07', '2015-07-07'] location = ['San Diego, CA', 'Bellev ...
-
根据您的更新,您需要具有两个索引列的pivot_table - v = df1.pivot_table( index=['Entity', 'Name'], columns='Date', values='Value' ).reset_index() v.index.name = v.columns.name = None v Entity Name 2018-01-31 2018-02-28 2018-03-31 0 111 ...
-
Pandas数据框转动(Pandas dataframe pivoting)[2023-12-29]
您可以使用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 s ... -
在重复删除附加列的同时旋转Pandas数据帧(Pivoting a Pandas dataframe while deduplicating additional columns)[2023-07-19]
使用set_index和set_index In [2087]: df.set_index(['foo', 'extra', 'bar'])['baz'].unstack().reset_index() Out[2087]: bar foo extra A B C 0 one x 1 2 3 1 two y 4 5 6 Use set_index and unstack In [2087]: df.set_index(['foo', 'extra', 'ba ... -
在熊猫中复杂的旋转(Complex pivoting in pandas)[2022-02-24]
这是一种方式 In [237]: dff = (df.groupby(['A','B','C','D','E','F'])['G'].unique() .....: .apply(pd.Series, 1).fillna(0)) In [238]: dff.columns = ['G_%s' % (x+1) for x in dff.columns] In [239]: dff Out[239]: G_1 ... -
你想要这个吗? df.reset_index() 编辑:要删除轴名称cost ,您需要使用: df.rename_axis(None, axis=1).reset_index() 这仍然会返回一个索引,这就是pandas的工作方式,但它不会有浮动的标签。 如果你想cycle作为索引而没有cost ,你可以使用第一部分: df.rename_axis(None, axis=1) Do you want this? df.reset_index() Edit: To drop the axis name ...