Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google app engine 会话中的Twitter4j请求令牌(Google App Engine中的Struts2)_Google App Engine_Struts2_Twitter4j - Fatal编程技术网

Google app engine 会话中的Twitter4j请求令牌(Google App Engine中的Struts2)

Google app engine 会话中的Twitter4j请求令牌(Google App Engine中的Struts2),google-app-engine,struts2,twitter4j,Google App Engine,Struts2,Twitter4j,在我的操作中,我存储了请求令牌,如下所示: //TwitterOath public String execute(){ Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); try { RequestToken requestToken = twitter.getOAuthRequest

在我的操作中,我存储了请求令牌,如下所示:

//TwitterOath
public String execute(){
    Twitter twitter = new TwitterFactory().getInstance();
    twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);

    try {
        RequestToken requestToken = twitter.getOAuthRequestToken(REDIRECT_URI);
        authUrl = requestToken.getAuthenticationURL();

        //session
        Map<String, Object> session = ActionContext.getContext().getSession();
        session.put("requestToken", requestToken);

    } catch (TwitterException e) {
        e.printStackTrace();
    }

    return SUCCESS;
}

问题是,有时requestToken为null

有什么线索吗?我在许多应用程序中使用了基于会话的令牌机制,但还没有看到这样的错误/异常。如果你不知道的话,仍然可以将令牌存储在数据库中。我仍在研究这一点。您可以随时回复将请求令牌存储在数据库中。我相信您对访问令牌和请求令牌感到困惑,因为它们都用于不同的目的
Access\u令牌
是Oauth提供商提供的用于访问用户数据的令牌,它就像一个用户配置文件的密钥。推特通过不设置
Access\u令牌的任何到期日
使它变得更容易。
RequestToken requestToken = (RequestToken)
    ActionContext.getContext().getSession().get("requestToken");