Announcement Announcement Module
Collapse
No announcement yet.
FaceBook status update failing with 403 Forbidden error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • FaceBook status update failing with 403 Forbidden error

    Hi,
    I tried to connect to FaceBook Account and I am able to connect and seeing my picture and details. But when i tried to update the status I am getting 403 forbidden error.

    Can anyone help me to resolve this?

  • #2
    What means are you using to get a Facebook access token? Using the <fb:login-button> or are you using the OAuth 2 web server profile?

    In either event, when your application requests authorization from Facebook, have you requested "publish_stream" permissions in the scope parameter? If you're using the <fb:login-button>, you'll need to be sure to pass "publish_stream" in the perms attribute. If you're using the OAuth 2 web server profile, then be sure to pass it as the value of the scope parameter sent to the authorization URL.

    If you've done that and still can't post, give more details on how you're obtaining the access token and I'll see if I can spot the problem.

    Comment


    • #3
      Hi,

      I am using oAuth for getting access token.

      Code:
      String fb_oath_uri = "https://graph.facebook.com/oauth/";
      
      public String fbLoginAuthenticate() {
              return "redirect:"+ fb_oath_uri +"authorize?" +
                      "client_id=" + clientId +
                      "&display=page&redirect_uri=" + redirectURI;
          }
      
       private String assembleAuthentication(String authCode) {
              return fb_oath_uri + "access_token?" +
                      "client_id=" + clientId +
                      "&redirect_uri=" + redirectURI +
                      "&client_secret="+ secret +
                      "&code="+authCode;
          }
       
          public String retrieveAccessToken(String code){
              String accessToken = null;
              if (null != code) {
                  String authURL = assembleAuthentication(code);
                  URL uri = null;
                  try {
                      uri = new URL(authURL);
                      String result = crawlToURL(uri);
                      String[] values = result.split("&");
                      for (String value : values) {
                          String[] valuePair = value.split("=");
                          if (valuePair.length != 2) {
                              throw new RuntimeException("Unexpected auth response");
                          } else {
                              if (valuePair[0].equals("access_token")) {
                                  accessToken = valuePair[1];
                              }
                          }
                      }
                  } catch (MalformedURLException e) {
                      throw new RuntimeException(e);
                  }
              }
              return accessToken;
          }
       
          private String crawlToURL(URL uri) {
              ByteArrayOutputStream byteOutputStream = null;
              InputStream inputStream = null;
              String stream = null;
              try {
                  inputStream = uri.openStream();
                  byteOutputStream = new ByteArrayOutputStream();
                  int i;
                  while ((i = inputStream.read()) != -1) {
                      byteOutputStream.write(i);
                  }
                  stream = new String(byteOutputStream.toByteArray());
              } catch (IOException e) {
                  throw new RuntimeException(e);
              }finally {
                  if (null != byteOutputStream) {
                      try {
                          byteOutputStream.close();
                      } catch (IOException e) {
                          //do some logging here instead of printStackTrace()
                          e.printStackTrace();
                      }
                  }
       
                  if (null != inputStream) {
                      try {
                          inputStream.close();
                      } catch (IOException e) {
                          //do some logging here instead of printStackTrace()
                          e.printStackTrace();
                      }
                  }
              }
       
              return stream;
       
          }
      Where should i pass the "publish_stream" perms attribute?

      Comment


      • #4
        In your fbLoginAuthenticate() method, as a scope parameter to the authorization URL...something like this:

        Code:
        public String fbLoginAuthenticate() {
                return "redirect:"+ fb_oath_uri +"authorize?" +
                        "client_id=" + clientId +
                        "&display=page&redirect_uri=" + redirectURI +
                        "&scope=publish_stream";
            }
        Note that the scope parameter takes a comma-delimited list, so you can ask permission for a variety of different things. See http://developers.facebook.com/docs/...on/permissions for details on what kinds of permission you may ask for from Facebook.

        Comment


        • #5
          Wow..Its working now.
          Thanks a lot :-)

          Comment


          • #6
            hi,

            where are you getting this value "&code="+authCode?

            Thanks,

            Gerald

            Comment


            • #7
              Could you please share the code on how you made this working?

              Thanks,

              Comment


              • #8
                Originally posted by sivaprasadreddy.k View Post
                Wow..Its working now.
                Thanks a lot :-)
                Hi sivapradreddy,

                Can you share how you handle the oauth dance in spring?

                Comment


                • #9
                  Help

                  please show how you did this, im very confused

                  Comment


                  • #10
                    Sample- OAuth example

                    http://www.adobocode.com/spring/acce...spring-social/

                    Comment

                    Working...
                    X