Posts tagged with java

I'm encountering an issue with the Google Ads API where I'm receiving the following error message:

Credentials failed to obtain metadata

This error occurs when making requests to the Google Ads API using the GoogleAdsService/Search method. Here's an example of the request and response details:

Request

MethodName: google.ads.googleads.v16.services.GoogleAdsService/Search Endpoint: googleads.googleapis.com:443 Headers: {developer-token=REDACTED, login-customer-id=9854212609, x-goog-api-client=gl-java/17.0.10__Oracle-Corporation gccl/31.0.0 gapic/31.0.0 gax/2.47.0 grpc/1.62.2} Body: customer_id: "9854212609" query: "SELECT campaign.id, campaign.name FROM campaign" 

Response

Headers: null Body: null Failure message: null Status: Status{code=UNAVAILABLE, description=Credentials failed to obtain metadata, cause=com.google.auth.oauth2.GoogleAuthException: com.google.api.client.http.HttpResponseException: 401 Unauthorized POST https://oauth2.googleapis.com/token 

...

Here are the details of my configuration:

  • I'm using Spring Boot for my application.
  • I have a google-ads.properties file where I've configured the necessary credentials such as clientId, clientSecret, refreshToken, developerToken, and loginCustomerId.
  • I've implemented the Google Ads client using the GoogleAdsClient class provided by the Google Ads Java library.
  • I've verified that the credentials are correct and have the necessary permissions to access the Google Ads API.

Despite these configurations, I'm still encountering the error mentioned above. I'm not sure what could be causing the issue. Any insights or suggestions on how to troubleshoot and resolve this would be greatly appreciated.

Thank you in advance for your help!

based on the provided error message and the details of the configuration, I expected the Google Ads API requests to authenticate successfully and return the requested data. However, the actual result was a failure with the message "Credentials failed to obtain metadata," indicating an authentication issue.

I am using Facebook graph API Facebook graph API, to update my Instagram page's post create/ update. the endpoint I am using is like

https://graph.facebook.com/{media_id}?caption={new_caption}&access_token={access_token} 

Neither using insomnia nor using JAVA code do I receive the successful message, and the caption remains unchanged.

    private static CompletableFuture<PostFB> updatePostInstagramMessageAsync(String hostname, PostFB ig, HttpClient client) {     JSONObject jsonPayload = new JSONObject();     if (ig.text != null && !ig.text.isEmpty()) {         jsonPayload.put("caption", ig.text);           jsonPayload.put("comment_enabled", true);           System.out.println("jsonPayload is " + jsonPayload.toString());         String url = "https://graph.facebook.com/v19.0/" + "my postID";         HttpRequest request = HttpRequest.newBuilder()                 .uri(URI.create(url + "?access_token=" + ig.page_access_token))                 .header("Content-Type", "application/json")                 .method("POST", BodyPublishers.ofString(jsonPayload.toString(), StandardCharsets.UTF_8))                 .build();         return client.sendAsync(request, HttpResponse.BodyHandlers.ofString())                 .thenApply(response -> {                     System.out.println("Response for updating post is " + response.body());                     if (response.statusCode() == 200) {                                                       System.out.println("Updated post successfully.");                         } else {                             System.out.println("Failed to update post: " + response.body());                                                     }                     } else {                         System.out.println("Failed to update post. Status code: " + response.statusCode());                                             }                     return ig;                 })                 .exceptionally(ex -> {                     ex.printStackTrace();                                         return ig;                 });     } else {         return CompletableFuture.completedFuture(null);     } } 

Despite receiving a successful response, the caption does not change. I have created the application and assigned the necessary permissions:

  • pages_show_list,
  • instagram_basic,
  • instagram_manage_comments,
  • instagram_manage_insights,
  • instagram_content_publish,
  • instagram_manage_messages,
  • pages_read_engagement,
  • instagram_manage_events,
  • public_profile

I am able to create new posts but I cannot modify them. Why? any help would be appriciated.

i wish to find a solution to this issue i have been facing for a long while, trying to publish a reel on instagram. It keeps returning this error: Media upload has failed with error code 2207026 which means its not in the required format, i have tried with countless videos, uploaded them to my google drive and input the link to the video but still the same error, i came across this: Facebook Graph API - Getting error 2207026 when trying to upload video

And also implemented the last suggesstion in my code as shown below:

public String uploadFile(MultipartFile file) {         String extension = StringUtils.getFilenameExtension(file.getOriginalFilename());         var key = UUID.randomUUID() + "." + extension;         String directory = this.fileStorageLocation;         Path newPath = Paths.get(directory).toAbsolutePath().normalize();         try {             Files.createDirectories(newPath);             Path inputFilePath = newPath.resolve(StringUtils.cleanPath(key));             Path outputFilePath = newPath.resolve("output.mp4");             Files.copy(file.getInputStream(), inputFilePath, StandardCopyOption.REPLACE_EXISTING);             executeFFmpegCommand(inputFilePath.toString(), outputFilePath.toString());         } catch (IOException ex) {             Logger.getLogger(FileService.class.getName()).log(Level.SEVERE, null, ex);         }         return key;     }     private void executeFFmpegCommand(String inputFilePath, String outputFilePath) throws IOException {         String ffmpegPath = "C:\\ffmpeg\\bin\\ffmpeg.exe";         String[] ffmpegCommand = {                 ffmpegPath,                 "-i", inputFilePath,                 "-c:v", "libx264",                 "-aspect", "16:9",                 "-crf", "18",                 "-vf", "scale=iw*min(1280/iw\\,720/ih):ih*min(1280/iw\\,720/ih),pad=1280:720:(1280-iw)/2:(720-ih)/2",                 "-fpsmax", "60",                 "-preset", "ultrafast",                 "-c:a", "aac",                 "-b:a", "128k",                 "-ac", "1",                 "-pix_fmt", "yuv420p",                 "-movflags", "+faststart",                 "-t", "59",                 "-y", outputFilePath         };         ProcessBuilder processBuilder = new ProcessBuilder(ffmpegCommand);         processBuilder.inheritIO();         Process process = processBuilder.start();         try {             process.waitFor();             System.out.println("FFmpeg command executed successfully.");         } catch (InterruptedException e) {             throw new IOException("Error executing FFmpeg command: " + e.getMessage(), e);         }     } 

And uploaded the video to my drive and put in the link again, but still the same error, i dont know could be the issue, could someone provide a suggestion or a link to a video that has been tested with, because i dont see what am doing wrong, thanks.

i have been trying to publish videos on a facebook page's story, but i havent been successful, i have tried using their apis and integrating with restfb as well, As for restfb, i was able to post on a facebook page's timeline, but not on their story, i have included the code showing my implementation using the facebook api and rest fb, thanks for checking out, i appreciate any assistance

public void postVideo(String contentUrl) throws MalformedURLException, FileNotFoundException, FacebookOAuthException {         Users loggedInUser = userService.getCurrentUser();         Socials social = socialsService.getSocialByPlatform(SocialPlatform.FACEBOOK);         UserSocials userSocial= userSocialsService.findUserSocial(loggedInUser, social).orElseThrow(()-> new UserException("User social not found"));         FacebookClient defaultFacebookClient = new DefaultFacebookClient(userSocial.getAccessToken(), Version.LATEST);         File videoFile = new File("uploads/" + contentUrl);         if (!videoFile.exists()) {             throw new FileNotFoundException("Video file not found at specified path.");         }         FileInputStream fileInputStream = new FileInputStream(videoFile); //       Implementation using facebook api //        MultiValueMap<String, Object> requestBody = new LinkedMultiValueMap<>(); //        requestBody.add("file", new FileSystemResource("uploads/" + contentUrl)); //        HttpHeaders headers = new HttpHeaders(); //        headers.setContentType(MediaType.MULTIPART_FORM_DATA); //        FBVideoStoryStartResponse fbVideoStoryStartResponse = webClient.post() //                .uri("https://graph.facebook.com/v18.0/"+userSocial.getSocialUserId()+"/video_stories", uriBuilder -> uriBuilder //                        .queryParam("upload_phase", "start") //                        .build()) //                .retrieve() //                .bodyToMono(FBVideoStoryStartResponse.class) //                .block(); //        System.out.println(fbVideoStoryStartResponse); //        if(fbVideoStoryStartResponse != null){ //            FBVideoStoryUploadStatus fbVideoStoryUploadStatus = webClient.post() //                    .uri("https://rupload.facebook.com/video-upload/v18.0/" + fbVideoStoryStartResponse.getVideoId()) //                    .headers(httpHeaders -> httpHeaders.addAll(headers)) // Add the headers to the request //                    .bodyValue(requestBody) //                    .retrieve() //                    .bodyToMono(FBVideoStoryUploadStatus.class) //                    .block(); //            System.out.println(fbVideoStoryUploadStatus); //            assert fbVideoStoryUploadStatus != null; //            if(fbVideoStoryUploadStatus.isSuccess()){ //                FBVideoStoryFinishResponse fbVideoStoryFinishResponse = webClient.post() //                        .uri("https://graph.facebook.com/v18.0/"+userSocial.getSocialUserId()+"/video_stories", uriBuilder -> uriBuilder //                                .queryParam("video_id", fbVideoStoryStartResponse.getVideoId()) //                                .queryParam("upload_phase", "finish") //                                .build()) //                        .retrieve() //                        .bodyToMono(FBVideoStoryFinishResponse.class) //                        .block(); //                System.out.println(fbVideoStoryFinishResponse); //            } //        } //      Implementation using restfb         FBVideoStoryStartResponse fbVideoStoryStartResponse1 = defaultFacebookClient.publish(userSocial.getSocialUserId() + "/video_stories", FBVideoStoryStartResponse.class,                 Parameter.with("upload_phase", "start"));         String videoUploadID = fbVideoStoryStartResponse1.getVideoId();         System.out.println(videoUploadID);         GraphResponse graphResponse = defaultFacebookClient.publish(videoUploadID, GraphResponse.class, BinaryAttachment.with(videoFile.getName(), fileInputStream));         GraphResponse graphResponse1 = defaultFacebookClient.publish(userSocial.getSocialUserId() + "/video_stories", GraphResponse.class,                 Parameter.with("video_id", videoUploadID),                  Parameter.with("upload_phase", "finish"),                  Parameter.with("video_state", "PUBLISHED"),                 Parameter.with("description", "A short description text"));             try {                 fileInputStream.close();             } catch (IOException e) {                 throw new RuntimeException(e);             } } 

So using restfb, i get the error "There is a problem uploading your video, Please try again with another file" and i have tried with multiple files below a minute but still the same result.