Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate message #15

Closed
anddimario opened this issue Oct 30, 2012 · 0 comments
Closed

Duplicate message #15

anddimario opened this issue Oct 30, 2012 · 0 comments

Comments

@anddimario
Copy link

Hi, i've this code:

    // Set index route
    app.get('/', utils.accesslog, function(req, res){
        //Get token from session to allow post
        graph.setAccessToken(req.session.fb_token);
        console.log(req.session.fb_token); 
        var wallPost = {
          message: "Hello!"
        };
        // To post you need to authorize the applicationt to public_stream: http://facebook.com/authorize.php?api_key=MYAPPAPIKEY&v=1.0&ext_perm=publish_stream
        graph.post(req.session.fb_userId + "/feed", wallPost, function(err, results) {
          // returns the post id
              if (err){
              console.log(JSON.stringify(err)); // { id: xxxxx}
              }else {console.log(JSON.stringify(results));}
        });
        res.render('index', {connected: req.session.connected, title: configuration.Params.title, message: [{msg: "Hello" + req.session.fb_userId}]});

    });


    // Set facebook login path. On Facebook main parameter page set url as: mysite.tld/fblogin
    app.get('/fblogin', utils.accesslog, function(req, res){
        // we don't have a code yet
        // so we'll redirect to the oauth dialog
        if (!req.query.code) {
            var authUrl = graph.getOauthUrl({
                "client_id":     configuration.Params.facebook_appId,
                "redirect_uri":  configuration.Params.facebook_redirect_uri
            });

            if (!req.query.error) { //checks whether a user denied the app facebook login/permissions
                res.redirect(authUrl);
            } else {  //req.query.error == 'access_denied'
                res.send('access denied');
            }
            return;
        }

        // code is set
        // we'll send that and get the access token
        graph.authorize({
            "client_id":      configuration.Params.facebook_appId,
            "redirect_uri":   configuration.Params.facebook_redirect_uri,
            "client_secret":  configuration.Params.facebook_secret,
            "code":           req.query.code
        }, function (err, facebookRes) {
            console.log(facebookRes); 
            req.session.fb_token = facebookRes.access_token;  
          // Get user information and put them into session
            graph.get("me", function(err, user) {
                req.session.fb_userId = user.id;
                console.log(user); // { id: '4', name: 'Mark Zuckerberg'... }

                res.redirect('/');
            });
        });
    });```

I have two duplicate message to facebook:
{"id":"1657787844_3625402647858"}
{"message":"(#506) Duplicate status message","type":"OAuthException","code":506,"error_data":{"kError":1455006}}
It seems that pages is refreshed twice, probably i wrote something bad.

Had someone the same problem?

Thanks for your time.
Best regards.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant